descriptor.h 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2009-2021, Google LLC
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of Google LLC nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
  20. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef PYUPB_DESCRIPTOR_H__
  28. #define PYUPB_DESCRIPTOR_H__
  29. #include <stdbool.h>
  30. #include "python/python.h"
  31. #include "upb/def.h"
  32. typedef enum {
  33. kPyUpb_Descriptor = 0,
  34. kPyUpb_EnumDescriptor = 1,
  35. kPyUpb_EnumValueDescriptor = 2,
  36. kPyUpb_FieldDescriptor = 3,
  37. kPyUpb_FileDescriptor = 4,
  38. kPyUpb_MethodDescriptor = 5,
  39. kPyUpb_OneofDescriptor = 6,
  40. kPyUpb_ServiceDescriptor = 7,
  41. kPyUpb_Descriptor_Count = 8,
  42. } PyUpb_DescriptorType;
  43. // Given a descriptor object |desc|, returns a Python message class object for
  44. // the msgdef |m|, which must be from the same pool.
  45. PyObject* PyUpb_Descriptor_GetClass(const upb_MessageDef* m);
  46. // Returns a Python wrapper object for the given def. This will return an
  47. // existing object if one already exists, otherwise a new object will be
  48. // created. The caller always owns a ref on the returned object.
  49. PyObject* PyUpb_Descriptor_Get(const upb_MessageDef* msgdef);
  50. PyObject* PyUpb_EnumDescriptor_Get(const upb_EnumDef* enumdef);
  51. PyObject* PyUpb_FieldDescriptor_Get(const upb_FieldDef* field);
  52. PyObject* PyUpb_FileDescriptor_Get(const upb_FileDef* file);
  53. PyObject* PyUpb_OneofDescriptor_Get(const upb_OneofDef* oneof);
  54. PyObject* PyUpb_EnumValueDescriptor_Get(const upb_EnumValueDef* enumval);
  55. PyObject* PyUpb_Descriptor_GetOrCreateWrapper(const upb_MessageDef* msg);
  56. PyObject* PyUpb_ServiceDescriptor_Get(const upb_ServiceDef* s);
  57. PyObject* PyUpb_MethodDescriptor_Get(const upb_MethodDef* s);
  58. // Returns the underlying |def| for a given wrapper object. The caller must
  59. // have already verified that the given Python object is of the expected type.
  60. const upb_FileDef* PyUpb_FileDescriptor_GetDef(PyObject* file);
  61. const upb_FieldDef* PyUpb_FieldDescriptor_GetDef(PyObject* file);
  62. const upb_MessageDef* PyUpb_Descriptor_GetDef(PyObject* _self);
  63. const void* PyUpb_AnyDescriptor_GetDef(PyObject* _self);
  64. // Returns the underlying |def| for a given wrapper object. The caller must
  65. // have already verified that the given Python object is of the expected type.
  66. const upb_FileDef* PyUpb_FileDescriptor_GetDef(PyObject* file);
  67. const void* PyUpb_AnyDescriptor_GetDef(PyObject* _self);
  68. // Module-level init.
  69. bool PyUpb_InitDescriptor(PyObject* m);
  70. #endif // PYUPB_DESCRIPTOR_H__