OLD | NEW |
1 // Protocol Buffers - Google's data interchange format | 1 // Protocol Buffers - Google's data interchange format |
2 // Copyright 2008 Google Inc. All rights reserved. | 2 // Copyright 2008 Google Inc. All rights reserved. |
3 // https://developers.google.com/protocol-buffers/ | 3 // https://developers.google.com/protocol-buffers/ |
4 // | 4 // |
5 // Redistribution and use in source and binary forms, with or without | 5 // Redistribution and use in source and binary forms, with or without |
6 // modification, are permitted provided that the following conditions are | 6 // modification, are permitted provided that the following conditions are |
7 // met: | 7 // met: |
8 // | 8 // |
9 // * Redistributions of source code must retain the above copyright | 9 // * Redistributions of source code must retain the above copyright |
10 // notice, this list of conditions and the following disclaimer. | 10 // notice, this list of conditions and the following disclaimer. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 #define GPBNSStringify(S) @#S | 43 #define GPBNSStringify(S) @#S |
44 #define GPBNSStringifySymbol(S) GPBNSStringify(S) | 44 #define GPBNSStringifySymbol(S) GPBNSStringify(S) |
45 | 45 |
46 // Constant to internally mark when there is no has bit. | 46 // Constant to internally mark when there is no has bit. |
47 #define GPBNoHasBit INT32_MAX | 47 #define GPBNoHasBit INT32_MAX |
48 | 48 |
49 CF_EXTERN_C_BEGIN | 49 CF_EXTERN_C_BEGIN |
50 | 50 |
51 // These two are used to inject a runtime check for version mismatch into the | 51 // These two are used to inject a runtime check for version mismatch into the |
52 // generated sources to make sure they are linked with a supporting runtime. | 52 // generated sources to make sure they are linked with a supporting runtime. |
| 53 void GPBCheckRuntimeVersionSupport(int32_t objcRuntimeVersion); |
| 54 GPB_INLINE void GPB_DEBUG_CHECK_RUNTIME_VERSIONS() { |
| 55 // NOTE: By being inline here, this captures the value from the library's |
| 56 // headers at the time the generated code was compiled. |
| 57 #if defined(DEBUG) && DEBUG |
| 58 GPBCheckRuntimeVersionSupport(GOOGLE_PROTOBUF_OBJC_VERSION); |
| 59 #endif |
| 60 } |
| 61 |
| 62 // Legacy version of the checks, remove when GOOGLE_PROTOBUF_OBJC_GEN_VERSION |
| 63 // goes away (see more info in GPBBootstrap.h). |
53 void GPBCheckRuntimeVersionInternal(int32_t version); | 64 void GPBCheckRuntimeVersionInternal(int32_t version); |
54 GPB_INLINE void GPBDebugCheckRuntimeVersion() { | 65 GPB_INLINE void GPBDebugCheckRuntimeVersion() { |
55 #if DEBUG | 66 #if defined(DEBUG) && DEBUG |
56 GPBCheckRuntimeVersionInternal(GOOGLE_PROTOBUF_OBJC_GEN_VERSION); | 67 GPBCheckRuntimeVersionInternal(GOOGLE_PROTOBUF_OBJC_GEN_VERSION); |
57 #endif | 68 #endif |
58 } | 69 } |
59 | 70 |
60 // Conversion functions for de/serializing floating point types. | 71 // Conversion functions for de/serializing floating point types. |
61 | 72 |
62 GPB_INLINE int64_t GPBConvertDoubleToInt64(double v) { | 73 GPB_INLINE int64_t GPBConvertDoubleToInt64(double v) { |
63 union { double f; int64_t i; } u; | 74 union { double f; int64_t i; } u; |
64 u.f = v; | 75 u.f = v; |
65 return u.i; | 76 return u.i; |
(...skipping 23 matching lines...) Expand all Loading... |
89 | 100 |
90 GPB_INLINE int64_t GPBLogicalRightShift64(int64_t value, int32_t spaces) { | 101 GPB_INLINE int64_t GPBLogicalRightShift64(int64_t value, int32_t spaces) { |
91 return (int64_t)((uint64_t)(value) >> spaces); | 102 return (int64_t)((uint64_t)(value) >> spaces); |
92 } | 103 } |
93 | 104 |
94 // Decode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers | 105 // Decode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers |
95 // into values that can be efficiently encoded with varint. (Otherwise, | 106 // into values that can be efficiently encoded with varint. (Otherwise, |
96 // negative values must be sign-extended to 64 bits to be varint encoded, | 107 // negative values must be sign-extended to 64 bits to be varint encoded, |
97 // thus always taking 10 bytes on the wire.) | 108 // thus always taking 10 bytes on the wire.) |
98 GPB_INLINE int32_t GPBDecodeZigZag32(uint32_t n) { | 109 GPB_INLINE int32_t GPBDecodeZigZag32(uint32_t n) { |
99 return GPBLogicalRightShift32(n, 1) ^ -(n & 1); | 110 return (int32_t)(GPBLogicalRightShift32((int32_t)n, 1) ^ -((int32_t)(n) & 1)); |
100 } | 111 } |
101 | 112 |
102 // Decode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers | 113 // Decode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers |
103 // into values that can be efficiently encoded with varint. (Otherwise, | 114 // into values that can be efficiently encoded with varint. (Otherwise, |
104 // negative values must be sign-extended to 64 bits to be varint encoded, | 115 // negative values must be sign-extended to 64 bits to be varint encoded, |
105 // thus always taking 10 bytes on the wire.) | 116 // thus always taking 10 bytes on the wire.) |
106 GPB_INLINE int64_t GPBDecodeZigZag64(uint64_t n) { | 117 GPB_INLINE int64_t GPBDecodeZigZag64(uint64_t n) { |
107 return GPBLogicalRightShift64(n, 1) ^ -(n & 1); | 118 return (int64_t)(GPBLogicalRightShift64((int64_t)n, 1) ^ -((int64_t)(n) & 1)); |
108 } | 119 } |
109 | 120 |
110 // Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers | 121 // Encode a ZigZag-encoded 32-bit value. ZigZag encodes signed integers |
111 // into values that can be efficiently encoded with varint. (Otherwise, | 122 // into values that can be efficiently encoded with varint. (Otherwise, |
112 // negative values must be sign-extended to 64 bits to be varint encoded, | 123 // negative values must be sign-extended to 64 bits to be varint encoded, |
113 // thus always taking 10 bytes on the wire.) | 124 // thus always taking 10 bytes on the wire.) |
114 GPB_INLINE uint32_t GPBEncodeZigZag32(int32_t n) { | 125 GPB_INLINE uint32_t GPBEncodeZigZag32(int32_t n) { |
115 // Note: the right-shift must be arithmetic | 126 // Note: the right-shift must be arithmetic |
116 return (n << 1) ^ (n >> 31); | 127 return (uint32_t)((n << 1) ^ (n >> 31)); |
117 } | 128 } |
118 | 129 |
119 // Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers | 130 // Encode a ZigZag-encoded 64-bit value. ZigZag encodes signed integers |
120 // into values that can be efficiently encoded with varint. (Otherwise, | 131 // into values that can be efficiently encoded with varint. (Otherwise, |
121 // negative values must be sign-extended to 64 bits to be varint encoded, | 132 // negative values must be sign-extended to 64 bits to be varint encoded, |
122 // thus always taking 10 bytes on the wire.) | 133 // thus always taking 10 bytes on the wire.) |
123 GPB_INLINE uint64_t GPBEncodeZigZag64(int64_t n) { | 134 GPB_INLINE uint64_t GPBEncodeZigZag64(int64_t n) { |
124 // Note: the right-shift must be arithmetic | 135 // Note: the right-shift must be arithmetic |
125 return (n << 1) ^ (n >> 63); | 136 return (uint64_t)((n << 1) ^ (n >> 63)); |
126 } | 137 } |
127 | 138 |
| 139 #pragma clang diagnostic push |
| 140 #pragma clang diagnostic ignored "-Wswitch-enum" |
| 141 #pragma clang diagnostic ignored "-Wdirect-ivar-access" |
| 142 |
128 GPB_INLINE BOOL GPBDataTypeIsObject(GPBDataType type) { | 143 GPB_INLINE BOOL GPBDataTypeIsObject(GPBDataType type) { |
129 switch (type) { | 144 switch (type) { |
130 case GPBDataTypeBytes: | 145 case GPBDataTypeBytes: |
131 case GPBDataTypeString: | 146 case GPBDataTypeString: |
132 case GPBDataTypeMessage: | 147 case GPBDataTypeMessage: |
133 case GPBDataTypeGroup: | 148 case GPBDataTypeGroup: |
134 return YES; | 149 return YES; |
135 default: | 150 default: |
136 return NO; | 151 return NO; |
137 } | 152 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 } | 195 } |
181 GPB_INLINE void GPBSetHasIvarField(GPBMessage *self, GPBFieldDescriptor *field, | 196 GPB_INLINE void GPBSetHasIvarField(GPBMessage *self, GPBFieldDescriptor *field, |
182 BOOL value) { | 197 BOOL value) { |
183 GPBMessageFieldDescription *fieldDesc = field->description_; | 198 GPBMessageFieldDescription *fieldDesc = field->description_; |
184 GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, value); | 199 GPBSetHasIvar(self, fieldDesc->hasIndex, fieldDesc->number, value); |
185 } | 200 } |
186 | 201 |
187 void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof, | 202 void GPBMaybeClearOneof(GPBMessage *self, GPBOneofDescriptor *oneof, |
188 int32_t oneofHasIndex, uint32_t fieldNumberNotToClear); | 203 int32_t oneofHasIndex, uint32_t fieldNumberNotToClear); |
189 | 204 |
| 205 #pragma clang diagnostic pop |
| 206 |
190 //%PDDM-DEFINE GPB_IVAR_SET_DECL(NAME, TYPE) | 207 //%PDDM-DEFINE GPB_IVAR_SET_DECL(NAME, TYPE) |
191 //%void GPBSet##NAME##IvarWithFieldInternal(GPBMessage *self, | 208 //%void GPBSet##NAME##IvarWithFieldInternal(GPBMessage *self, |
192 //% NAME$S GPBFieldDescriptor *field, | 209 //% NAME$S GPBFieldDescriptor *field, |
193 //% NAME$S TYPE value, | 210 //% NAME$S TYPE value, |
194 //% NAME$S GPBFileSyntax syntax); | 211 //% NAME$S GPBFileSyntax syntax); |
195 //%PDDM-EXPAND GPB_IVAR_SET_DECL(Bool, BOOL) | 212 //%PDDM-EXPAND GPB_IVAR_SET_DECL(Bool, BOOL) |
196 // This block of code is generated, do not edit it directly. | 213 // This block of code is generated, do not edit it directly. |
197 | 214 |
198 void GPBSetBoolIvarWithFieldInternal(GPBMessage *self, | 215 void GPBSetBoolIvarWithFieldInternal(GPBMessage *self, |
199 GPBFieldDescriptor *field, | 216 GPBFieldDescriptor *field, |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 339 |
323 #undef GPB_MESSAGE_SIGNATURE_ENTRY | 340 #undef GPB_MESSAGE_SIGNATURE_ENTRY |
324 | 341 |
325 - (id)getArray; | 342 - (id)getArray; |
326 - (NSUInteger)getArrayCount; | 343 - (NSUInteger)getArrayCount; |
327 - (void)setArray:(NSArray *)array; | 344 - (void)setArray:(NSArray *)array; |
328 + (id)getClassValue; | 345 + (id)getClassValue; |
329 @end | 346 @end |
330 | 347 |
331 CF_EXTERN_C_END | 348 CF_EXTERN_C_END |
OLD | NEW |