protobuf/python/google/protobuf/pyext/descriptor_pool.h
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
31 #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__
32 #define GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__
33 
34 #define PY_SSIZE_T_CLEAN
35 #include <Python.h>
36 
37 #include <unordered_map>
38 #include <google/protobuf/descriptor.h>
39 
40 namespace google {
41 namespace protobuf {
42 namespace python {
43 
44 struct PyMessageFactory;
45 
46 // The (meta) type of all Messages classes.
47 struct CMessageClass;
48 
49 // Wraps operations to the global DescriptorPool which contains information
50 // about all messages and fields.
51 //
52 // There is normally one pool per process. We make it a Python object only
53 // because it contains many Python references.
54 //
55 // "Methods" that interacts with this DescriptorPool are in the cdescriptor_pool
56 // namespace.
57 typedef struct PyDescriptorPool {
59 
60  // The C++ pool containing Descriptors.
62 
63  // True if we should free the pointer above.
64  bool is_owned;
65 
66  // True if this pool accepts new proto definitions.
67  // In this case it is allowed to const_cast<DescriptorPool*>(pool).
68  bool is_mutable;
69 
70 
71  // The error collector to store error info. Can be NULL. This pointer is
72  // owned.
73  DescriptorPool::ErrorCollector* error_collector;
74 
75  // The C++ pool acting as an underlay. Can be NULL.
76  // This pointer is not owned and must stay alive.
77  const DescriptorPool* underlay;
78 
79  // The C++ descriptor database used to fetch unknown protos. Can be NULL.
80  // This pointer is owned.
82 
83  // The preferred MessageFactory to be used by descriptors.
84  // TODO(amauryfa): Don't create the Factory from the DescriptorPool, but
85  // use the one passed while creating message classes. And remove this member.
87 
88  // Cache the options for any kind of descriptor.
89  // Descriptor pointers are owned by the DescriptorPool above.
90  // Python objects are owned by the map.
91  std::unordered_map<const void*, PyObject*>* descriptor_options;
93 
94 
95 extern PyTypeObject PyDescriptorPool_Type;
96 
97 namespace cdescriptor_pool {
98 
99 
100 // The functions below are also exposed as methods of the DescriptorPool type.
101 
102 // Looks up a field by name. Returns a PyFieldDescriptor corresponding to
103 // the field on success, or NULL on failure.
104 //
105 // Returns a new reference.
106 PyObject* FindFieldByName(PyDescriptorPool* self, PyObject* name);
107 
108 // Looks up an extension by name. Returns a PyFieldDescriptor corresponding
109 // to the field on success, or NULL on failure.
110 //
111 // Returns a new reference.
112 PyObject* FindExtensionByName(PyDescriptorPool* self, PyObject* arg);
113 
114 // Looks up an enum type by name. Returns a PyEnumDescriptor corresponding
115 // to the field on success, or NULL on failure.
116 //
117 // Returns a new reference.
118 PyObject* FindEnumTypeByName(PyDescriptorPool* self, PyObject* arg);
119 
120 // Looks up a oneof by name. Returns a COneofDescriptor corresponding
121 // to the oneof on success, or NULL on failure.
122 //
123 // Returns a new reference.
124 PyObject* FindOneofByName(PyDescriptorPool* self, PyObject* arg);
125 
126 } // namespace cdescriptor_pool
127 
128 // Retrieves the global descriptor pool owned by the _message module.
129 // This is the one used by pb2.py generated modules.
130 // Returns a *borrowed* reference.
131 // "Default" pool used to register messages from _pb2.py modules.
133 
134 // Retrieves an existing python descriptor pool owning the C++ descriptor pool.
135 // Returns a *borrowed* reference.
137 
138 // Wraps a C++ descriptor pool in a Python object, creates it if necessary.
139 // Returns a new reference.
141 
142 // Initialize objects used by this module.
143 bool InitDescriptorPool();
144 
145 } // namespace python
146 } // namespace protobuf
147 } // namespace google
148 
149 #endif // GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_POOL_H__
google::protobuf::python::cdescriptor_pool::FindEnumTypeByName
PyObject * FindEnumTypeByName(PyDescriptorPool *self, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:318
google::protobuf::python::cdescriptor_pool::FindOneofByName
PyObject * FindOneofByName(PyDescriptorPool *self, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:339
google::protobuf::python::PyMessageFactory
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/message_factory.h:49
google::protobuf::python::GetDefaultDescriptorPool
PyDescriptorPool * GetDefaultDescriptorPool()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:751
google::protobuf::python::PyDescriptorPool
struct google::protobuf::python::PyDescriptorPool PyDescriptorPool
google::protobuf
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:12
setup.name
name
Definition: setup.py:542
google::protobuf::python::PyDescriptorPool_FromPool
PyObject * PyDescriptorPool_FromPool(const DescriptorPool *pool)
Definition: protobuf/python/google/protobuf/pyext/descriptor_pool.cc:783
google::protobuf::python::PyDescriptorPool
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h:56
google::protobuf::python::GetDescriptorPool_FromPool
PyDescriptorPool * GetDescriptorPool_FromPool(const DescriptorPool *pool)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:755
google::protobuf::python::cdescriptor_pool::FindFieldByName
PyObject * FindFieldByName(PyDescriptorPool *self, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:275
google::protobuf::python::cdescriptor_pool::FindExtensionByName
PyObject * FindExtensionByName(PyDescriptorPool *self, PyObject *arg)
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:296
google::protobuf::python::PyDescriptorPool::py_message_factory
PyMessageFactory * py_message_factory
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h:77
google::protobuf::DescriptorPool
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor.h:1539
arg
Definition: cmdline.cc:40
google::protobuf::python::PyDescriptorPool::is_mutable
bool is_mutable
Definition: protobuf/python/google/protobuf/pyext/descriptor_pool.h:68
google::protobuf::python::PyDescriptorPool::PyObject_HEAD
PyObject_HEAD
Definition: protobuf/python/google/protobuf/pyext/descriptor_pool.h:58
google::protobuf::DescriptorDatabase
Definition: bloaty/third_party/protobuf/src/google/protobuf/descriptor_database.h:71
google::protobuf::python::PyDescriptorPool::is_owned
bool is_owned
Definition: protobuf/python/google/protobuf/pyext/descriptor_pool.h:64
google::protobuf::python::PyDescriptorPool_Type
PyTypeObject PyDescriptorPool_Type
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:677
google::protobuf::python::PyDescriptorPool::descriptor_options
std::unordered_map< const void *, PyObject * > * descriptor_options
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h:82
google::protobuf::python::PyDescriptorPool::underlay
const DescriptorPool * underlay
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h:68
google::protobuf::python::PyDescriptorPool::database
const DescriptorDatabase * database
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h:72
google::protobuf::python::InitDescriptorPool
bool InitDescriptorPool()
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.cc:723
google::protobuf::python::PyDescriptorPool::error_collector
DescriptorPool::ErrorCollector * error_collector
Definition: bloaty/third_party/protobuf/python/google/protobuf/pyext/descriptor_pool.h:64
pool
InternalDescriptorPool * pool
Definition: bloaty/third_party/protobuf/php/ext/google/protobuf/protobuf.h:807
google::protobuf::python::PyDescriptorPool::pool
const DescriptorPool * pool
Definition: protobuf/python/google/protobuf/pyext/descriptor_pool.h:61
google
Definition: bloaty/third_party/protobuf/benchmarks/util/data_proto2_to_proto3_util.h:11


grpc
Author(s):
autogenerated on Fri May 16 2025 02:58:15