blob: 013f1d8ca789cc3db99bb8197b6eaf4985751beb [file] [log] [blame]
Adam Cozzette501ecec2023-09-26 14:36:20 -07001// Protocol Buffers - Google's data interchange format
2// Copyright 2023 Google LLC. All rights reserved.
Adam Cozzette501ecec2023-09-26 14:36:20 -07003//
Protobuf Team Bot0fab7732023-11-20 13:38:15 -08004// 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 Cozzette501ecec2023-09-26 14:36:20 -07007
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
16typedef 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.
30PyObject* PyUpb_Descriptor_GetClass(const upb_MessageDef* m);
31
32// Set the message descriptor's meta class.
33void 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.
38PyObject* PyUpb_Descriptor_Get(const upb_MessageDef* msgdef);
39PyObject* PyUpb_EnumDescriptor_Get(const upb_EnumDef* enumdef);
40PyObject* PyUpb_FieldDescriptor_Get(const upb_FieldDef* field);
41PyObject* PyUpb_FileDescriptor_Get(const upb_FileDef* file);
42PyObject* PyUpb_OneofDescriptor_Get(const upb_OneofDef* oneof);
43PyObject* PyUpb_EnumValueDescriptor_Get(const upb_EnumValueDef* enumval);
44PyObject* PyUpb_Descriptor_GetOrCreateWrapper(const upb_MessageDef* msg);
45PyObject* PyUpb_ServiceDescriptor_Get(const upb_ServiceDef* s);
46PyObject* 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.
50const upb_FileDef* PyUpb_FileDescriptor_GetDef(PyObject* file);
51const upb_FieldDef* PyUpb_FieldDescriptor_GetDef(PyObject* file);
52const upb_MessageDef* PyUpb_Descriptor_GetDef(PyObject* _self);
53const 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.
57const upb_FileDef* PyUpb_FileDescriptor_GetDef(PyObject* file);
58
59// Module-level init.
60bool PyUpb_InitDescriptor(PyObject* m);
61
62#endif // PYUPB_DESCRIPTOR_H__