• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_DEF_H_
9 #define PHP_PROTOBUF_DEF_H_
10 
11 #include <php.h>
12 
13 #include "php-upb.h"
14 
15 // Initializes the Def module, which defines all of the descriptor classes.
16 void Def_ModuleInit();
17 
18 // Creates a new DescriptorPool to wrap the given symtab, which must not be
19 // NULL.
20 void DescriptorPool_CreateWithSymbolTable(zval* zv, upb_DefPool* symtab);
21 
22 upb_DefPool* DescriptorPool_GetSymbolTable();
23 
24 // Returns true if the global descriptor pool already has the given filename.
25 bool DescriptorPool_HasFile(const char* filename);
26 
27 // Adds the given descriptor with the given filename to the global pool.
28 void DescriptorPool_AddDescriptor(const char* filename, const char* data,
29                                   int size);
30 
31 typedef struct Descriptor {
32   zend_object std;
33   const upb_MessageDef* msgdef;
34   zend_class_entry* class_entry;
35 } Descriptor;
36 
37 // Gets or creates a Descriptor* for the given class entry, upb_MessageDef, or
38 // upb_FieldDef. The returned Descriptor* will live for the entire request,
39 // so no ref is necessary to keep it alive. The caller does *not* own a ref
40 // on the returned object.
41 Descriptor* Descriptor_GetFromClassEntry(zend_class_entry* ce);
42 Descriptor* Descriptor_GetFromMessageDef(const upb_MessageDef* m);
43 Descriptor* Descriptor_GetFromFieldDef(const upb_FieldDef* f);
44 
45 // Packages up a upb_CType with a Descriptor, since many functions need
46 // both.
47 typedef struct {
48   upb_CType type;
49   const Descriptor* desc;  // When type == kUpb_CType_Message.
50 } TypeInfo;
51 
TypeInfo_Get(const upb_FieldDef * f)52 static inline TypeInfo TypeInfo_Get(const upb_FieldDef* f) {
53   TypeInfo ret = {upb_FieldDef_CType(f), Descriptor_GetFromFieldDef(f)};
54   return ret;
55 }
56 
TypeInfo_FromType(upb_CType type)57 static inline TypeInfo TypeInfo_FromType(upb_CType type) {
58   TypeInfo ret = {type};
59   return ret;
60 }
61 
TypeInfo_Eq(TypeInfo a,TypeInfo b)62 static inline bool TypeInfo_Eq(TypeInfo a, TypeInfo b) {
63   if (a.type != b.type) return false;
64   if (a.type == kUpb_CType_Message && a.desc != b.desc) return false;
65   return true;
66 }
67 
68 #endif  // PHP_PROTOBUF_DEF_H_
69