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