店播爬取Python脚本

descriptor.h 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. // Author: petar@google.com (Petar Petrov)
  31. #ifndef GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_H__
  32. #define GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_H__
  33. #include <Python.h>
  34. #include <google/protobuf/descriptor.h>
  35. namespace google {
  36. namespace protobuf {
  37. namespace python {
  38. // Should match the type of ConstStringParam.
  39. using StringParam = std::string;
  40. extern PyTypeObject PyMessageDescriptor_Type;
  41. extern PyTypeObject PyFieldDescriptor_Type;
  42. extern PyTypeObject PyEnumDescriptor_Type;
  43. extern PyTypeObject PyEnumValueDescriptor_Type;
  44. extern PyTypeObject PyFileDescriptor_Type;
  45. extern PyTypeObject PyOneofDescriptor_Type;
  46. extern PyTypeObject PyServiceDescriptor_Type;
  47. extern PyTypeObject PyMethodDescriptor_Type;
  48. // Wraps a Descriptor in a Python object.
  49. // The C++ pointer is usually borrowed from the global DescriptorPool.
  50. // In any case, it must stay alive as long as the Python object.
  51. // Returns a new reference.
  52. PyObject* PyMessageDescriptor_FromDescriptor(const Descriptor* descriptor);
  53. PyObject* PyFieldDescriptor_FromDescriptor(const FieldDescriptor* descriptor);
  54. PyObject* PyEnumDescriptor_FromDescriptor(const EnumDescriptor* descriptor);
  55. PyObject* PyEnumValueDescriptor_FromDescriptor(
  56. const EnumValueDescriptor* descriptor);
  57. PyObject* PyOneofDescriptor_FromDescriptor(const OneofDescriptor* descriptor);
  58. PyObject* PyFileDescriptor_FromDescriptor(
  59. const FileDescriptor* file_descriptor);
  60. PyObject* PyServiceDescriptor_FromDescriptor(
  61. const ServiceDescriptor* descriptor);
  62. PyObject* PyMethodDescriptor_FromDescriptor(
  63. const MethodDescriptor* descriptor);
  64. // Alternate constructor of PyFileDescriptor, used when we already have a
  65. // serialized FileDescriptorProto that can be cached.
  66. // Returns a new reference.
  67. PyObject* PyFileDescriptor_FromDescriptorWithSerializedPb(
  68. const FileDescriptor* file_descriptor, PyObject* serialized_pb);
  69. // Return the C++ descriptor pointer.
  70. // This function checks the parameter type; on error, return NULL with a Python
  71. // exception set.
  72. const Descriptor* PyMessageDescriptor_AsDescriptor(PyObject* obj);
  73. const FieldDescriptor* PyFieldDescriptor_AsDescriptor(PyObject* obj);
  74. const EnumDescriptor* PyEnumDescriptor_AsDescriptor(PyObject* obj);
  75. const FileDescriptor* PyFileDescriptor_AsDescriptor(PyObject* obj);
  76. const ServiceDescriptor* PyServiceDescriptor_AsDescriptor(PyObject* obj);
  77. // Returns the raw C++ pointer.
  78. const void* PyDescriptor_AsVoidPtr(PyObject* obj);
  79. // Check that the calling Python code is the global scope of a _pb2.py module.
  80. // This function is used to support the current code generated by the proto
  81. // compiler, which insists on modifying descriptors after they have been
  82. // created.
  83. //
  84. // stacklevel indicates which Python frame should be the _pb2.py module.
  85. //
  86. // Don't use this function outside descriptor classes.
  87. bool _CalledFromGeneratedFile(int stacklevel);
  88. bool InitDescriptor();
  89. } // namespace python
  90. } // namespace protobuf
  91. } // namespace google
  92. #endif // GOOGLE_PROTOBUF_PYTHON_CPP_DESCRIPTOR_H__