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 PHP_PROTOBUF_MAP_H_ 9 #define PHP_PROTOBUF_MAP_H_ 10 11 #include <php.h> 12 13 #include "def.h" 14 #include "php-upb.h" 15 16 void Map_ModuleInit(); 17 18 typedef struct { 19 upb_CType key_type; 20 TypeInfo val_type; 21 } MapField_Type; 22 23 MapField_Type MapType_Get(const upb_FieldDef* f); 24 25 // Gets a upb_Map* for the PHP object |val|: 26 // * If |val| is a RepeatedField object, we first check its type and verify 27 // that that the elements have the correct type for |f|. If so, we return the 28 // wrapped upb_Map*. We also make sure that this map's arena is fused to 29 // |arena|, so the returned upb_Map is guaranteed to live as long as 30 // |arena|. 31 // * If |val| is a PHP Map, we attempt to create a new upb_Map using 32 // |arena| and add all of the PHP elements to it. 33 // 34 // If an error occurs, we raise a PHP error and return NULL. 35 upb_Map* MapField_GetUpbMap(zval* val, MapField_Type type, upb_Arena* arena); 36 37 // Creates a PHP MapField object for the given upb_Map* and |f| and returns it 38 // in |val|. The PHP object will keep a reference to this |arena| to ensure the 39 // underlying array data stays alive. 40 // 41 // If |map| is NULL, this will return a PHP null object. 42 void MapField_GetPhpWrapper(zval* val, upb_Map* arr, MapField_Type type, 43 zval* arena); 44 45 bool MapEq(const upb_Map* m1, const upb_Map* m2, MapField_Type type); 46 47 #endif // PHP_PROTOBUF_MAP_H_ 48