GPBRuntimeTypes.h 3.7 KB

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