| 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 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 // This header is private to the ProtobolBuffers library and must NOT be | 31 // This header is private to the ProtobolBuffers library and must NOT be |
| 32 // included by any sources outside this library. The contents of this file are | 32 // included by any sources outside this library. The contents of this file are |
| 33 // subject to change at any time without notice. | 33 // subject to change at any time without notice. |
| 34 | 34 |
| 35 #import "GPBDescriptor.h" | 35 #import "GPBDescriptor.h" |
| 36 #import "GPBWireFormat.h" | 36 #import "GPBWireFormat.h" |
| 37 | 37 |
| 38 // Describes attributes of the field. | 38 // Describes attributes of the field. |
| 39 typedef NS_OPTIONS(uint16_t, GPBFieldFlags) { | 39 typedef NS_OPTIONS(uint16_t, GPBFieldFlags) { |
| 40 GPBFieldNone = 0, |
| 40 // These map to standard protobuf concepts. | 41 // These map to standard protobuf concepts. |
| 41 GPBFieldRequired = 1 << 0, | 42 GPBFieldRequired = 1 << 0, |
| 42 GPBFieldRepeated = 1 << 1, | 43 GPBFieldRepeated = 1 << 1, |
| 43 GPBFieldPacked = 1 << 2, | 44 GPBFieldPacked = 1 << 2, |
| 44 GPBFieldOptional = 1 << 3, | 45 GPBFieldOptional = 1 << 3, |
| 45 GPBFieldHasDefaultValue = 1 << 4, | 46 GPBFieldHasDefaultValue = 1 << 4, |
| 46 | 47 |
| 47 // Indicates the field needs custom handling for the TextFormat name, if not | 48 // Indicates the field needs custom handling for the TextFormat name, if not |
| 48 // set, the name can be derived from the ObjC name. | 49 // set, the name can be derived from the ObjC name. |
| 49 GPBFieldTextFormatNameCustom = 1 << 6, | 50 GPBFieldTextFormatNameCustom = 1 << 6, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // value. This struct provides the default along with the field info. | 105 // value. This struct provides the default along with the field info. |
| 105 typedef struct GPBMessageFieldDescriptionWithDefault { | 106 typedef struct GPBMessageFieldDescriptionWithDefault { |
| 106 // Default value for the ivar. | 107 // Default value for the ivar. |
| 107 GPBGenericValue defaultValue; | 108 GPBGenericValue defaultValue; |
| 108 | 109 |
| 109 GPBMessageFieldDescription core; | 110 GPBMessageFieldDescription core; |
| 110 } GPBMessageFieldDescriptionWithDefault; | 111 } GPBMessageFieldDescriptionWithDefault; |
| 111 | 112 |
| 112 // Describes attributes of the extension. | 113 // Describes attributes of the extension. |
| 113 typedef NS_OPTIONS(uint8_t, GPBExtensionOptions) { | 114 typedef NS_OPTIONS(uint8_t, GPBExtensionOptions) { |
| 115 GPBExtensionNone = 0, |
| 114 // These map to standard protobuf concepts. | 116 // These map to standard protobuf concepts. |
| 115 GPBExtensionRepeated = 1 << 0, | 117 GPBExtensionRepeated = 1 << 0, |
| 116 GPBExtensionPacked = 1 << 1, | 118 GPBExtensionPacked = 1 << 1, |
| 117 GPBExtensionSetWireFormat = 1 << 2, | 119 GPBExtensionSetWireFormat = 1 << 2, |
| 118 }; | 120 }; |
| 119 | 121 |
| 120 // An extension | 122 // An extension |
| 121 typedef struct GPBExtensionDescription { | 123 typedef struct GPBExtensionDescription { |
| 122 GPBGenericValue defaultValue; | 124 GPBGenericValue defaultValue; |
| 123 const char *singletonName; | 125 const char *singletonName; |
| 124 const char *extendedClass; | 126 const char *extendedClass; |
| 125 const char *messageOrGroupClassName; | 127 const char *messageOrGroupClassName; |
| 126 GPBEnumDescriptorFunc enumDescriptorFunc; | 128 GPBEnumDescriptorFunc enumDescriptorFunc; |
| 127 int32_t fieldNumber; | 129 int32_t fieldNumber; |
| 128 GPBDataType dataType; | 130 GPBDataType dataType; |
| 129 GPBExtensionOptions options; | 131 GPBExtensionOptions options; |
| 130 } GPBExtensionDescription; | 132 } GPBExtensionDescription; |
| 131 | 133 |
| 132 typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) { | 134 typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) { |
| 135 GPBDescriptorInitializationFlag_None = 0, |
| 133 GPBDescriptorInitializationFlag_FieldsWithDefault = 1 << 0, | 136 GPBDescriptorInitializationFlag_FieldsWithDefault = 1 << 0, |
| 134 GPBDescriptorInitializationFlag_WireFormat = 1 << 1, | 137 GPBDescriptorInitializationFlag_WireFormat = 1 << 1, |
| 135 }; | 138 }; |
| 136 | 139 |
| 137 @interface GPBDescriptor () { | 140 @interface GPBDescriptor () { |
| 138 @package | 141 @package |
| 139 NSArray *fields_; | 142 NSArray *fields_; |
| 140 NSArray *oneofs_; | 143 NSArray *oneofs_; |
| 141 uint32_t storageSize_; | 144 uint32_t storageSize_; |
| 142 } | 145 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 158 wireFormat:(BOOL)wireFormat; | 161 wireFormat:(BOOL)wireFormat; |
| 159 | 162 |
| 160 // Called right after init to provide extra information to avoid init having | 163 // Called right after init to provide extra information to avoid init having |
| 161 // an explosion of args. These pointers are recorded, so they are expected | 164 // an explosion of args. These pointers are recorded, so they are expected |
| 162 // to live for the lifetime of the app. | 165 // to live for the lifetime of the app. |
| 163 - (void)setupOneofs:(const char **)oneofNames | 166 - (void)setupOneofs:(const char **)oneofNames |
| 164 count:(uint32_t)count | 167 count:(uint32_t)count |
| 165 firstHasIndex:(int32_t)firstHasIndex; | 168 firstHasIndex:(int32_t)firstHasIndex; |
| 166 - (void)setupExtraTextInfo:(const char *)extraTextFormatInfo; | 169 - (void)setupExtraTextInfo:(const char *)extraTextFormatInfo; |
| 167 - (void)setupExtensionRanges:(const GPBExtensionRange *)ranges count:(int32_t)co
unt; | 170 - (void)setupExtensionRanges:(const GPBExtensionRange *)ranges count:(int32_t)co
unt; |
| 171 - (void)setupContainingMessageClassName:(const char *)msgClassName; |
| 172 - (void)setupMessageClassNameSuffix:(NSString *)suffix; |
| 168 | 173 |
| 169 @end | 174 @end |
| 170 | 175 |
| 171 @interface GPBFileDescriptor () | 176 @interface GPBFileDescriptor () |
| 172 - (instancetype)initWithPackage:(NSString *)package | 177 - (instancetype)initWithPackage:(NSString *)package |
| 178 objcPrefix:(NSString *)objcPrefix |
| 179 syntax:(GPBFileSyntax)syntax; |
| 180 - (instancetype)initWithPackage:(NSString *)package |
| 173 syntax:(GPBFileSyntax)syntax; | 181 syntax:(GPBFileSyntax)syntax; |
| 174 @end | 182 @end |
| 175 | 183 |
| 176 @interface GPBOneofDescriptor () { | 184 @interface GPBOneofDescriptor () { |
| 177 @package | 185 @package |
| 178 const char *name_; | 186 const char *name_; |
| 179 NSArray *fields_; | 187 NSArray *fields_; |
| 180 SEL caseSel_; | 188 SEL caseSel_; |
| 181 } | 189 } |
| 182 // name must be long lived. | 190 // name must be long lived. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 @property(nonatomic, readonly) GPBWireFormat alternateWireType; | 246 @property(nonatomic, readonly) GPBWireFormat alternateWireType; |
| 239 | 247 |
| 240 // description has to be long lived, it is held as a raw pointer. | 248 // description has to be long lived, it is held as a raw pointer. |
| 241 - (instancetype)initWithExtensionDescription: | 249 - (instancetype)initWithExtensionDescription: |
| 242 (GPBExtensionDescription *)description; | 250 (GPBExtensionDescription *)description; |
| 243 - (NSComparisonResult)compareByFieldNumber:(GPBExtensionDescriptor *)other; | 251 - (NSComparisonResult)compareByFieldNumber:(GPBExtensionDescriptor *)other; |
| 244 @end | 252 @end |
| 245 | 253 |
| 246 CF_EXTERN_C_BEGIN | 254 CF_EXTERN_C_BEGIN |
| 247 | 255 |
| 256 // Direct access is use for speed, to avoid even internally declaring things |
| 257 // read/write, etc. The warning is enabled in the project to ensure code calling |
| 258 // protos can turn on -Wdirect-ivar-access without issues. |
| 259 #pragma clang diagnostic push |
| 260 #pragma clang diagnostic ignored "-Wdirect-ivar-access" |
| 261 |
| 248 GPB_INLINE BOOL GPBFieldIsMapOrArray(GPBFieldDescriptor *field) { | 262 GPB_INLINE BOOL GPBFieldIsMapOrArray(GPBFieldDescriptor *field) { |
| 249 return (field->description_->flags & | 263 return (field->description_->flags & |
| 250 (GPBFieldRepeated | GPBFieldMapKeyMask)) != 0; | 264 (GPBFieldRepeated | GPBFieldMapKeyMask)) != 0; |
| 251 } | 265 } |
| 252 | 266 |
| 253 GPB_INLINE GPBDataType GPBGetFieldDataType(GPBFieldDescriptor *field) { | 267 GPB_INLINE GPBDataType GPBGetFieldDataType(GPBFieldDescriptor *field) { |
| 254 return field->description_->dataType; | 268 return field->description_->dataType; |
| 255 } | 269 } |
| 256 | 270 |
| 257 GPB_INLINE int32_t GPBFieldHasIndex(GPBFieldDescriptor *field) { | 271 GPB_INLINE int32_t GPBFieldHasIndex(GPBFieldDescriptor *field) { |
| 258 return field->description_->hasIndex; | 272 return field->description_->hasIndex; |
| 259 } | 273 } |
| 260 | 274 |
| 261 GPB_INLINE uint32_t GPBFieldNumber(GPBFieldDescriptor *field) { | 275 GPB_INLINE uint32_t GPBFieldNumber(GPBFieldDescriptor *field) { |
| 262 return field->description_->number; | 276 return field->description_->number; |
| 263 } | 277 } |
| 264 | 278 |
| 279 #pragma clang diagnostic pop |
| 280 |
| 265 uint32_t GPBFieldTag(GPBFieldDescriptor *self); | 281 uint32_t GPBFieldTag(GPBFieldDescriptor *self); |
| 266 | 282 |
| 267 // For repeated fields, alternateWireType is the wireType with the opposite | 283 // For repeated fields, alternateWireType is the wireType with the opposite |
| 268 // value for the packable property. i.e. - if the field was marked packed it | 284 // value for the packable property. i.e. - if the field was marked packed it |
| 269 // would be the wire type for unpacked; if the field was marked unpacked, it | 285 // would be the wire type for unpacked; if the field was marked unpacked, it |
| 270 // would be the wire type for packed. | 286 // would be the wire type for packed. |
| 271 uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self); | 287 uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self); |
| 272 | 288 |
| 273 GPB_INLINE BOOL GPBPreserveUnknownFields(GPBFileSyntax syntax) { | 289 GPB_INLINE BOOL GPBPreserveUnknownFields(GPBFileSyntax syntax) { |
| 274 return syntax != GPBFileSyntaxProto3; | 290 return syntax != GPBFileSyntaxProto3; |
| 275 } | 291 } |
| 276 | 292 |
| 277 GPB_INLINE BOOL GPBHasPreservingUnknownEnumSemantics(GPBFileSyntax syntax) { | 293 GPB_INLINE BOOL GPBHasPreservingUnknownEnumSemantics(GPBFileSyntax syntax) { |
| 278 return syntax == GPBFileSyntaxProto3; | 294 return syntax == GPBFileSyntaxProto3; |
| 279 } | 295 } |
| 280 | 296 |
| 281 GPB_INLINE BOOL GPBExtensionIsRepeated(GPBExtensionDescription *description) { | 297 GPB_INLINE BOOL GPBExtensionIsRepeated(GPBExtensionDescription *description) { |
| 282 return (description->options & GPBExtensionRepeated) != 0; | 298 return (description->options & GPBExtensionRepeated) != 0; |
| 283 } | 299 } |
| 284 | 300 |
| 285 GPB_INLINE BOOL GPBExtensionIsPacked(GPBExtensionDescription *description) { | 301 GPB_INLINE BOOL GPBExtensionIsPacked(GPBExtensionDescription *description) { |
| 286 return (description->options & GPBExtensionPacked) != 0; | 302 return (description->options & GPBExtensionPacked) != 0; |
| 287 } | 303 } |
| 288 | 304 |
| 289 GPB_INLINE BOOL GPBExtensionIsWireFormat(GPBExtensionDescription *description) { | 305 GPB_INLINE BOOL GPBExtensionIsWireFormat(GPBExtensionDescription *description) { |
| 290 return (description->options & GPBExtensionSetWireFormat) != 0; | 306 return (description->options & GPBExtensionSetWireFormat) != 0; |
| 291 } | 307 } |
| 292 | 308 |
| 293 // Helper for compile time assets. | 309 // Helper for compile time assets. |
| 294 #ifndef _GPBCompileAssert | 310 #ifndef GPBInternalCompileAssert |
| 295 #if __has_feature(c_static_assert) || __has_extension(c_static_assert) | 311 #if __has_feature(c_static_assert) || __has_extension(c_static_assert) |
| 296 #define _GPBCompileAssert(test, msg) _Static_assert((test), #msg) | 312 #define GPBInternalCompileAssert(test, msg) _Static_assert((test), #msg) |
| 297 #else | 313 #else |
| 298 // Pre-Xcode 7 support. | 314 // Pre-Xcode 7 support. |
| 299 #define _GPBCompileAssertSymbolInner(line, msg) _GPBCompileAssert ## line ##
__ ## msg | 315 #define GPBInternalCompileAssertSymbolInner(line, msg) GPBInternalCompileAss
ert ## line ## __ ## msg |
| 300 #define _GPBCompileAssertSymbol(line, msg) _GPBCompileAssertSymbolInner(line
, msg) | 316 #define GPBInternalCompileAssertSymbol(line, msg) GPBInternalCompileAssertSy
mbolInner(line, msg) |
| 301 #define _GPBCompileAssert(test, msg) \ | 317 #define GPBInternalCompileAssert(test, msg) \ |
| 302 typedef char _GPBCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1)
] | 318 typedef char GPBInternalCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1
: -1) ] |
| 303 #endif // __has_feature(c_static_assert) || __has_extension(c_static_assert) | 319 #endif // __has_feature(c_static_assert) || __has_extension(c_static_assert) |
| 304 #endif // _GPBCompileAssert | 320 #endif // GPBInternalCompileAssert |
| 305 | 321 |
| 306 // Sanity check that there isn't padding between the field description | 322 // Sanity check that there isn't padding between the field description |
| 307 // structures with and without a default. | 323 // structures with and without a default. |
| 308 _GPBCompileAssert(sizeof(GPBMessageFieldDescriptionWithDefault) == | 324 GPBInternalCompileAssert(sizeof(GPBMessageFieldDescriptionWithDefault) == |
| 309 (sizeof(GPBGenericValue) + | 325 (sizeof(GPBGenericValue) + |
| 310 sizeof(GPBMessageFieldDescription)), | 326 sizeof(GPBMessageFieldDescription)), |
| 311 DescriptionsWithDefault_different_size_than_expected); | 327 DescriptionsWithDefault_different_size_than_expected); |
| 312 | 328 |
| 313 CF_EXTERN_C_END | 329 CF_EXTERN_C_END |
| OLD | NEW |