Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 1 | // Protocol Buffers - Google's data interchange format |
| 2 | // Copyright 2023 Google LLC. All rights reserved. |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 3 | // |
Protobuf Team Bot | 0fab773 | 2023-11-20 13:38:15 -0800 | [diff] [blame] | 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 |
Adam Cozzette | 501ecec | 2023-09-26 14:36:20 -0700 | [diff] [blame] | 7 | |
| 8 | #ifndef PYUPB_DESCRIPTOR_H__ |
| 9 | #define PYUPB_DESCRIPTOR_H__ |
| 10 | |
| 11 | #include <stdbool.h> |
| 12 | |
| 13 | #include "python/python_api.h" |
| 14 | #include "upb/reflection/def.h" |
| 15 | |
| 16 | typedef enum { |
| 17 | kPyUpb_Descriptor = 0, |
| 18 | kPyUpb_EnumDescriptor = 1, |
| 19 | kPyUpb_EnumValueDescriptor = 2, |
| 20 | kPyUpb_FieldDescriptor = 3, |
| 21 | kPyUpb_FileDescriptor = 4, |
| 22 | kPyUpb_MethodDescriptor = 5, |
| 23 | kPyUpb_OneofDescriptor = 6, |
| 24 | kPyUpb_ServiceDescriptor = 7, |
| 25 | kPyUpb_Descriptor_Count = 8, |
| 26 | } PyUpb_DescriptorType; |
| 27 | |
| 28 | // Given a descriptor object |desc|, returns a Python message class object for |
| 29 | // the msgdef |m|, which must be from the same pool. |
| 30 | PyObject* PyUpb_Descriptor_GetClass(const upb_MessageDef* m); |
| 31 | |
| 32 | // Set the message descriptor's meta class. |
| 33 | void PyUpb_Descriptor_SetClass(PyObject* py_descriptor, PyObject* meta); |
| 34 | |
| 35 | // Returns a Python wrapper object for the given def. This will return an |
| 36 | // existing object if one already exists, otherwise a new object will be |
| 37 | // created. The caller always owns a ref on the returned object. |
| 38 | PyObject* PyUpb_Descriptor_Get(const upb_MessageDef* msgdef); |
| 39 | PyObject* PyUpb_EnumDescriptor_Get(const upb_EnumDef* enumdef); |
| 40 | PyObject* PyUpb_FieldDescriptor_Get(const upb_FieldDef* field); |
| 41 | PyObject* PyUpb_FileDescriptor_Get(const upb_FileDef* file); |
| 42 | PyObject* PyUpb_OneofDescriptor_Get(const upb_OneofDef* oneof); |
| 43 | PyObject* PyUpb_EnumValueDescriptor_Get(const upb_EnumValueDef* enumval); |
| 44 | PyObject* PyUpb_Descriptor_GetOrCreateWrapper(const upb_MessageDef* msg); |
| 45 | PyObject* PyUpb_ServiceDescriptor_Get(const upb_ServiceDef* s); |
| 46 | PyObject* PyUpb_MethodDescriptor_Get(const upb_MethodDef* s); |
| 47 | |
| 48 | // Returns the underlying |def| for a given wrapper object. The caller must |
| 49 | // have already verified that the given Python object is of the expected type. |
| 50 | const upb_FileDef* PyUpb_FileDescriptor_GetDef(PyObject* file); |
| 51 | const upb_FieldDef* PyUpb_FieldDescriptor_GetDef(PyObject* file); |
| 52 | const upb_MessageDef* PyUpb_Descriptor_GetDef(PyObject* _self); |
| 53 | const void* PyUpb_AnyDescriptor_GetDef(PyObject* _self); |
| 54 | |
| 55 | // Returns the underlying |def| for a given wrapper object. The caller must |
| 56 | // have already verified that the given Python object is of the expected type. |
| 57 | const upb_FileDef* PyUpb_FileDescriptor_GetDef(PyObject* file); |
| 58 | |
| 59 | // Module-level init. |
| 60 | bool PyUpb_InitDescriptor(PyObject* m); |
| 61 | |
| 62 | #endif // PYUPB_DESCRIPTOR_H__ |