GPBRuntimeTypes.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. #import <Foundation/Foundation.h>
  31. #import "GPBBootstrap.h"
  32. @class GPBEnumDescriptor;
  33. @class GPBMessage;
  34. @class GPBInt32Array;
  35. /**
  36. * Verifies that a given value can be represented by an enum type.
  37. * */
  38. typedef BOOL (*GPBEnumValidationFunc)(int32_t);
  39. /**
  40. * Fetches an EnumDescriptor.
  41. * */
  42. typedef GPBEnumDescriptor *(*GPBEnumDescriptorFunc)(void);
  43. /**
  44. * Magic value used at runtime to indicate an enum value that wasn't know at
  45. * compile time.
  46. * */
  47. enum {
  48. kGPBUnrecognizedEnumeratorValue = (int32_t)0xFBADBEEF,
  49. };
  50. /**
  51. * A union for storing all possible Protobuf values. Note that owner is
  52. * responsible for memory management of object types.
  53. * */
  54. typedef union {
  55. BOOL valueBool;
  56. int32_t valueInt32;
  57. int64_t valueInt64;
  58. uint32_t valueUInt32;
  59. uint64_t valueUInt64;
  60. float valueFloat;
  61. double valueDouble;
  62. GPB_UNSAFE_UNRETAINED NSData *valueData;
  63. GPB_UNSAFE_UNRETAINED NSString *valueString;
  64. GPB_UNSAFE_UNRETAINED GPBMessage *valueMessage;
  65. int32_t valueEnum;
  66. } GPBGenericValue;
  67. /**
  68. * Enum listing the possible data types that a field can contain.
  69. *
  70. * @note Do not change the order of this enum (or add things to it) without
  71. * thinking about it very carefully. There are several things that depend
  72. * on the order.
  73. * */
  74. typedef NS_ENUM(uint8_t, GPBDataType) {
  75. /** Field contains boolean value(s). */
  76. GPBDataTypeBool = 0,
  77. /** Field contains unsigned 4 byte value(s). */
  78. GPBDataTypeFixed32,
  79. /** Field contains signed 4 byte value(s). */
  80. GPBDataTypeSFixed32,
  81. /** Field contains float value(s). */
  82. GPBDataTypeFloat,
  83. /** Field contains unsigned 8 byte value(s). */
  84. GPBDataTypeFixed64,
  85. /** Field contains signed 8 byte value(s). */
  86. GPBDataTypeSFixed64,
  87. /** Field contains double value(s). */
  88. GPBDataTypeDouble,
  89. /**
  90. * Field contains variable length value(s). Inefficient for encoding negative
  91. * numbers – if your field is likely to have negative values, use
  92. * GPBDataTypeSInt32 instead.
  93. **/
  94. GPBDataTypeInt32,
  95. /**
  96. * Field contains variable length value(s). Inefficient for encoding negative
  97. * numbers – if your field is likely to have negative values, use
  98. * GPBDataTypeSInt64 instead.
  99. **/
  100. GPBDataTypeInt64,
  101. /** Field contains signed variable length integer value(s). */
  102. GPBDataTypeSInt32,
  103. /** Field contains signed variable length integer value(s). */
  104. GPBDataTypeSInt64,
  105. /** Field contains unsigned variable length integer value(s). */
  106. GPBDataTypeUInt32,
  107. /** Field contains unsigned variable length integer value(s). */
  108. GPBDataTypeUInt64,
  109. /** Field contains an arbitrary sequence of bytes. */
  110. GPBDataTypeBytes,
  111. /** Field contains UTF-8 encoded or 7-bit ASCII text. */
  112. GPBDataTypeString,
  113. /** Field contains message type(s). */
  114. GPBDataTypeMessage,
  115. /** Field contains message type(s). */
  116. GPBDataTypeGroup,
  117. /** Field contains enum value(s). */
  118. GPBDataTypeEnum,
  119. };
  120. enum {
  121. /**
  122. * A count of the number of types in GPBDataType. Separated out from the
  123. * GPBDataType enum to avoid warnings regarding not handling GPBDataType_Count
  124. * in switch statements.
  125. **/
  126. GPBDataType_Count = GPBDataTypeEnum + 1
  127. };
  128. /** An extension range. */
  129. typedef struct GPBExtensionRange {
  130. /** Inclusive. */
  131. uint32_t start;
  132. /** Exclusive. */
  133. uint32_t end;
  134. } GPBExtensionRange;
  135. /**
  136. A type to represent an Objective C class.
  137. This is actually an `objc_class` but the runtime headers will not allow us to
  138. reference `objc_class`, so we have defined our own.
  139. */
  140. typedef struct GPBObjcClass_t GPBObjcClass_t;