1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 #ifndef RUBY_PROTOBUF_MAP_H_ 9 #define RUBY_PROTOBUF_MAP_H_ 10 11 #include "protobuf.h" 12 #include "ruby-upb.h" 13 14 // Returns a frozen sentinel Ruby wrapper object for an empty upb_Map with the 15 // key and value types specified by the field. Creates one if it doesn't exist. 16 VALUE Map_EmptyFrozen(const upb_FieldDef* f); 17 18 // Returns a Ruby wrapper object for the given map, which will be created if 19 // one does not exist already. 20 VALUE Map_GetRubyWrapper(const upb_Map *map, upb_CType key_type, 21 TypeInfo value_type, VALUE arena); 22 23 // Gets the underlying upb_Map for this Ruby map object, which must have 24 // key/value type that match |field|. If this is not a map or the type doesn't 25 // match, raises an exception. 26 const upb_Map *Map_GetUpbMap(VALUE val, const upb_FieldDef *field, 27 upb_Arena *arena); 28 29 // Implements #inspect for this map by appending its contents to |b|. 30 void Map_Inspect(StringBuilder *b, const upb_Map *map, upb_CType key_type, 31 TypeInfo val_type); 32 33 // Returns a new Hash object containing the contents of this Map. 34 VALUE Map_CreateHash(const upb_Map *map, upb_CType key_type, TypeInfo val_info); 35 36 // Returns a deep copy of this Map object. 37 VALUE Map_deep_copy(VALUE obj); 38 39 // Ruby class of Google::Protobuf::Map. 40 extern VALUE cMap; 41 42 // Call at startup to register all types in this module. 43 void Map_register(VALUE module); 44 45 // Recursively freeze map 46 VALUE Map_freeze(VALUE _self); 47 48 #endif // RUBY_PROTOBUF_MAP_H_ 49