Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 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 | |
| 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 |
| 33 | // subject to change at any time without notice. |
| 34 | |
| 35 | #import "GPBDescriptor.h" |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 36 | #import "GPBWireFormat.h" |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 37 | |
| 38 | // Describes attributes of the field. |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 39 | typedef NS_OPTIONS(uint16_t, GPBFieldFlags) { |
Sergio Campamá | 14e74f6 | 2016-09-08 12:15:12 -0700 | [diff] [blame] | 40 | GPBFieldNone = 0, |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 41 | // These map to standard protobuf concepts. |
| 42 | GPBFieldRequired = 1 << 0, |
| 43 | GPBFieldRepeated = 1 << 1, |
| 44 | GPBFieldPacked = 1 << 2, |
| 45 | GPBFieldOptional = 1 << 3, |
| 46 | GPBFieldHasDefaultValue = 1 << 4, |
| 47 | |
Thomas Van Lenten | 8d224b4 | 2020-04-08 11:34:37 -0400 | [diff] [blame] | 48 | // Indicate that the field should "clear" when set to zero value. This is the |
| 49 | // proto3 non optional behavior for singular data (ints, data, string, enum) |
| 50 | // fields. |
| 51 | GPBFieldClearHasIvarOnZero = 1 << 5, |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 52 | // Indicates the field needs custom handling for the TextFormat name, if not |
| 53 | // set, the name can be derived from the ObjC name. |
| 54 | GPBFieldTextFormatNameCustom = 1 << 6, |
| 55 | // Indicates the field has an enum descriptor. |
| 56 | GPBFieldHasEnumDescriptor = 1 << 7, |
| 57 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 58 | // These are not standard protobuf concepts, they are specific to the |
| 59 | // Objective C runtime. |
| 60 | |
| 61 | // These bits are used to mark the field as a map and what the key |
| 62 | // type is. |
| 63 | GPBFieldMapKeyMask = 0xF << 8, |
| 64 | GPBFieldMapKeyInt32 = 1 << 8, |
| 65 | GPBFieldMapKeyInt64 = 2 << 8, |
| 66 | GPBFieldMapKeyUInt32 = 3 << 8, |
| 67 | GPBFieldMapKeyUInt64 = 4 << 8, |
| 68 | GPBFieldMapKeySInt32 = 5 << 8, |
| 69 | GPBFieldMapKeySInt64 = 6 << 8, |
| 70 | GPBFieldMapKeyFixed32 = 7 << 8, |
| 71 | GPBFieldMapKeyFixed64 = 8 << 8, |
| 72 | GPBFieldMapKeySFixed32 = 9 << 8, |
| 73 | GPBFieldMapKeySFixed64 = 10 << 8, |
| 74 | GPBFieldMapKeyBool = 11 << 8, |
| 75 | GPBFieldMapKeyString = 12 << 8, |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 76 | }; |
| 77 | |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 78 | // NOTE: The structures defined here have their members ordered to minimize |
| 79 | // their size. This directly impacts the size of apps since these exist per |
| 80 | // field/extension. |
| 81 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 82 | // Describes a single field in a protobuf as it is represented as an ivar. |
| 83 | typedef struct GPBMessageFieldDescription { |
| 84 | // Name of ivar. |
| 85 | const char *name; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 86 | union { |
Dave MacLachlan | 74956e1 | 2019-12-17 17:32:09 -0800 | [diff] [blame] | 87 | // className is deprecated and will be removed in favor of clazz. |
| 88 | // kept around right now for backwards compatibility. |
| 89 | // clazz is used iff GPBDescriptorInitializationFlag_UsesClassRefs is set. |
| 90 | char *className; // Name of the class of the message. |
| 91 | Class clazz; // Class of the message. |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 92 | // For enums only: If EnumDescriptors are compiled in, it will be that, |
| 93 | // otherwise it will be the verifier. |
| 94 | GPBEnumDescriptorFunc enumDescFunc; |
| 95 | GPBEnumValidationFunc enumVerifier; |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 96 | } dataTypeSpecific; |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 97 | // The field number for the ivar. |
| 98 | uint32_t number; |
| 99 | // The index (in bits) into _has_storage_. |
| 100 | // >= 0: the bit to use for a value being set. |
| 101 | // = GPBNoHasBit(INT32_MAX): no storage used. |
| 102 | // < 0: in a oneOf, use a full int32 to record the field active. |
| 103 | int32_t hasIndex; |
| 104 | // Offset of the variable into it's structure struct. |
| 105 | uint32_t offset; |
| 106 | // Field flags. Use accessor functions below. |
| 107 | GPBFieldFlags flags; |
| 108 | // Data type of the ivar. |
| 109 | GPBDataType dataType; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 110 | } GPBMessageFieldDescription; |
| 111 | |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 112 | // Fields in messages defined in a 'proto2' syntax file can provide a default |
| 113 | // value. This struct provides the default along with the field info. |
| 114 | typedef struct GPBMessageFieldDescriptionWithDefault { |
| 115 | // Default value for the ivar. |
| 116 | GPBGenericValue defaultValue; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 117 | |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 118 | GPBMessageFieldDescription core; |
| 119 | } GPBMessageFieldDescriptionWithDefault; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 120 | |
| 121 | // Describes attributes of the extension. |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 122 | typedef NS_OPTIONS(uint8_t, GPBExtensionOptions) { |
Sergio Campamá | 14e74f6 | 2016-09-08 12:15:12 -0700 | [diff] [blame] | 123 | GPBExtensionNone = 0, |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 124 | // These map to standard protobuf concepts. |
| 125 | GPBExtensionRepeated = 1 << 0, |
| 126 | GPBExtensionPacked = 1 << 1, |
| 127 | GPBExtensionSetWireFormat = 1 << 2, |
| 128 | }; |
| 129 | |
| 130 | // An extension |
| 131 | typedef struct GPBExtensionDescription { |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 132 | GPBGenericValue defaultValue; |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 133 | const char *singletonName; |
Thomas Van Lenten | 2360bac | 2020-05-28 14:13:39 -0400 | [diff] [blame] | 134 | // Before 3.12, `extendedClass` was just a `const char *`. Thanks to nested |
| 135 | // initialization (https://en.cppreference.com/w/c/language/struct_initialization#Nested_initialization) |
| 136 | // old generated code with `.extendedClass = GPBStringifySymbol(Something)` |
| 137 | // still works; and the current generator can use `extendedClass.clazz`, to |
| 138 | // pass a Class reference. |
Dave MacLachlan | 74956e1 | 2019-12-17 17:32:09 -0800 | [diff] [blame] | 139 | union { |
| 140 | const char *name; |
| 141 | Class clazz; |
| 142 | } extendedClass; |
Thomas Van Lenten | 2360bac | 2020-05-28 14:13:39 -0400 | [diff] [blame] | 143 | // Before 3.12, this was `const char *messageOrGroupClassName`. In the |
| 144 | // initial 3.12 release, we moved the `union messageOrGroupClass`, and failed |
| 145 | // to realize that would break existing source code for extensions. So to |
| 146 | // keep existing source code working, we added an unnamed union (C11) to |
| 147 | // provide both the old field name and the new union. This keeps both older |
| 148 | // and newer code working. |
| 149 | // Background: https://github.com/protocolbuffers/protobuf/issues/7555 |
Dave MacLachlan | 74956e1 | 2019-12-17 17:32:09 -0800 | [diff] [blame] | 150 | union { |
Thomas Van Lenten | 2360bac | 2020-05-28 14:13:39 -0400 | [diff] [blame] | 151 | const char *messageOrGroupClassName; |
| 152 | union { |
| 153 | const char *name; |
| 154 | Class clazz; |
| 155 | } messageOrGroupClass; |
| 156 | }; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 157 | GPBEnumDescriptorFunc enumDescriptorFunc; |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 158 | int32_t fieldNumber; |
| 159 | GPBDataType dataType; |
| 160 | GPBExtensionOptions options; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 161 | } GPBExtensionDescription; |
| 162 | |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 163 | typedef NS_OPTIONS(uint32_t, GPBDescriptorInitializationFlags) { |
Sergio Campamá | 14e74f6 | 2016-09-08 12:15:12 -0700 | [diff] [blame] | 164 | GPBDescriptorInitializationFlag_None = 0, |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 165 | GPBDescriptorInitializationFlag_FieldsWithDefault = 1 << 0, |
| 166 | GPBDescriptorInitializationFlag_WireFormat = 1 << 1, |
Dave MacLachlan | 74956e1 | 2019-12-17 17:32:09 -0800 | [diff] [blame] | 167 | |
| 168 | // This is used as a stopgap as we move from using class names to class |
| 169 | // references. The runtime needs to support both until we allow a |
| 170 | // breaking change in the runtime. |
Thomas Van Lenten | 8d224b4 | 2020-04-08 11:34:37 -0400 | [diff] [blame] | 171 | GPBDescriptorInitializationFlag_UsesClassRefs = 1 << 2, |
| 172 | |
Thomas Van Lenten | dddeed2 | 2020-04-24 13:40:59 -0400 | [diff] [blame] | 173 | // This flag is used to indicate that the generated sources already contain |
Thomas Van Lenten | 8d224b4 | 2020-04-08 11:34:37 -0400 | [diff] [blame] | 174 | // the `GPBFieldClearHasIvarOnZero` flag and it doesn't have to be computed |
Thomas Van Lenten | dddeed2 | 2020-04-24 13:40:59 -0400 | [diff] [blame] | 175 | // at startup. This allows older generated code to still work with the |
Thomas Van Lenten | 8d224b4 | 2020-04-08 11:34:37 -0400 | [diff] [blame] | 176 | // current runtime library. |
| 177 | GPBDescriptorInitializationFlag_Proto3OptionalKnown = 1 << 3, |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 178 | }; |
| 179 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 180 | @interface GPBDescriptor () { |
| 181 | @package |
| 182 | NSArray *fields_; |
| 183 | NSArray *oneofs_; |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 184 | uint32_t storageSize_; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 185 | } |
| 186 | |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 187 | // fieldDescriptions have to be long lived, they are held as raw pointers. |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 188 | + (instancetype) |
| 189 | allocDescriptorForClass:(Class)messageClass |
| 190 | rootClass:(Class)rootClass |
| 191 | file:(GPBFileDescriptor *)file |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 192 | fields:(void *)fieldDescriptions |
| 193 | fieldCount:(uint32_t)fieldCount |
| 194 | storageSize:(uint32_t)storageSize |
| 195 | flags:(GPBDescriptorInitializationFlags)flags; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 196 | |
| 197 | - (instancetype)initWithClass:(Class)messageClass |
| 198 | file:(GPBFileDescriptor *)file |
| 199 | fields:(NSArray *)fields |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 200 | storageSize:(uint32_t)storage |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 201 | wireFormat:(BOOL)wireFormat; |
| 202 | |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 203 | // Called right after init to provide extra information to avoid init having |
| 204 | // an explosion of args. These pointers are recorded, so they are expected |
| 205 | // to live for the lifetime of the app. |
| 206 | - (void)setupOneofs:(const char **)oneofNames |
| 207 | count:(uint32_t)count |
| 208 | firstHasIndex:(int32_t)firstHasIndex; |
| 209 | - (void)setupExtraTextInfo:(const char *)extraTextFormatInfo; |
| 210 | - (void)setupExtensionRanges:(const GPBExtensionRange *)ranges count:(int32_t)count; |
Dave MacLachlan | 74956e1 | 2019-12-17 17:32:09 -0800 | [diff] [blame] | 211 | - (void)setupContainingMessageClass:(Class)msgClass; |
Thomas Van Lenten | 337ec30 | 2016-08-16 11:26:49 -0400 | [diff] [blame] | 212 | - (void)setupMessageClassNameSuffix:(NSString *)suffix; |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 213 | |
Dave MacLachlan | 74956e1 | 2019-12-17 17:32:09 -0800 | [diff] [blame] | 214 | // Deprecated. Use setupContainingMessageClass instead. |
| 215 | - (void)setupContainingMessageClassName:(const char *)msgClassName; |
| 216 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 217 | @end |
| 218 | |
| 219 | @interface GPBFileDescriptor () |
| 220 | - (instancetype)initWithPackage:(NSString *)package |
Thomas Van Lenten | 337ec30 | 2016-08-16 11:26:49 -0400 | [diff] [blame] | 221 | objcPrefix:(NSString *)objcPrefix |
| 222 | syntax:(GPBFileSyntax)syntax; |
| 223 | - (instancetype)initWithPackage:(NSString *)package |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 224 | syntax:(GPBFileSyntax)syntax; |
| 225 | @end |
| 226 | |
| 227 | @interface GPBOneofDescriptor () { |
| 228 | @package |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 229 | const char *name_; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 230 | NSArray *fields_; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 231 | SEL caseSel_; |
| 232 | } |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 233 | // name must be long lived. |
| 234 | - (instancetype)initWithName:(const char *)name fields:(NSArray *)fields; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 235 | @end |
| 236 | |
| 237 | @interface GPBFieldDescriptor () { |
| 238 | @package |
| 239 | GPBMessageFieldDescription *description_; |
| 240 | GPB_UNSAFE_UNRETAINED GPBOneofDescriptor *containingOneof_; |
| 241 | |
| 242 | SEL getSel_; |
| 243 | SEL setSel_; |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 244 | SEL hasOrCountSel_; // *Count for map<>/repeated fields, has* otherwise. |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 245 | SEL setHasSel_; |
| 246 | } |
| 247 | |
| 248 | // Single initializer |
| 249 | // description has to be long lived, it is held as a raw pointer. |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 250 | - (instancetype)initWithFieldDescription:(void *)description |
| 251 | includesDefault:(BOOL)includesDefault |
Dave MacLachlan | 74956e1 | 2019-12-17 17:32:09 -0800 | [diff] [blame] | 252 | usesClassRefs:(BOOL)usesClassRefs |
Thomas Van Lenten | 8d224b4 | 2020-04-08 11:34:37 -0400 | [diff] [blame] | 253 | proto3OptionalKnown:(BOOL)proto3OptionalKnown |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 254 | syntax:(GPBFileSyntax)syntax; |
Dave MacLachlan | 74956e1 | 2019-12-17 17:32:09 -0800 | [diff] [blame] | 255 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 256 | @end |
| 257 | |
| 258 | @interface GPBEnumDescriptor () |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 259 | // valueNames, values and extraTextFormatInfo have to be long lived, they are |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 260 | // held as raw pointers. |
| 261 | + (instancetype) |
| 262 | allocDescriptorForName:(NSString *)name |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 263 | valueNames:(const char *)valueNames |
| 264 | values:(const int32_t *)values |
| 265 | count:(uint32_t)valueCount |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 266 | enumVerifier:(GPBEnumValidationFunc)enumVerifier; |
| 267 | + (instancetype) |
| 268 | allocDescriptorForName:(NSString *)name |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 269 | valueNames:(const char *)valueNames |
| 270 | values:(const int32_t *)values |
| 271 | count:(uint32_t)valueCount |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 272 | enumVerifier:(GPBEnumValidationFunc)enumVerifier |
| 273 | extraTextFormatInfo:(const char *)extraTextFormatInfo; |
| 274 | |
| 275 | - (instancetype)initWithName:(NSString *)name |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 276 | valueNames:(const char *)valueNames |
| 277 | values:(const int32_t *)values |
| 278 | count:(uint32_t)valueCount |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 279 | enumVerifier:(GPBEnumValidationFunc)enumVerifier; |
| 280 | @end |
| 281 | |
| 282 | @interface GPBExtensionDescriptor () { |
| 283 | @package |
| 284 | GPBExtensionDescription *description_; |
| 285 | } |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 286 | @property(nonatomic, readonly) GPBWireFormat wireType; |
| 287 | |
| 288 | // For repeated extensions, alternateWireType is the wireType with the opposite |
| 289 | // value for the packable property. i.e. - if the extension was marked packed |
| 290 | // it would be the wire type for unpacked; if the extension was marked unpacked, |
| 291 | // it would be the wire type for packed. |
| 292 | @property(nonatomic, readonly) GPBWireFormat alternateWireType; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 293 | |
| 294 | // description has to be long lived, it is held as a raw pointer. |
Dave MacLachlan | 74956e1 | 2019-12-17 17:32:09 -0800 | [diff] [blame] | 295 | - (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc |
| 296 | usesClassRefs:(BOOL)usesClassRefs; |
| 297 | // Deprecated. Calls above with `usesClassRefs = NO` |
| 298 | - (instancetype)initWithExtensionDescription:(GPBExtensionDescription *)desc; |
| 299 | |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 300 | - (NSComparisonResult)compareByFieldNumber:(GPBExtensionDescriptor *)other; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 301 | @end |
| 302 | |
| 303 | CF_EXTERN_C_BEGIN |
| 304 | |
Thomas Van Lenten | c8a440d | 2016-05-25 13:46:00 -0400 | [diff] [blame] | 305 | // Direct access is use for speed, to avoid even internally declaring things |
| 306 | // read/write, etc. The warning is enabled in the project to ensure code calling |
| 307 | // protos can turn on -Wdirect-ivar-access without issues. |
| 308 | #pragma clang diagnostic push |
| 309 | #pragma clang diagnostic ignored "-Wdirect-ivar-access" |
| 310 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 311 | GPB_INLINE BOOL GPBFieldIsMapOrArray(GPBFieldDescriptor *field) { |
| 312 | return (field->description_->flags & |
| 313 | (GPBFieldRepeated | GPBFieldMapKeyMask)) != 0; |
| 314 | } |
| 315 | |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 316 | GPB_INLINE GPBDataType GPBGetFieldDataType(GPBFieldDescriptor *field) { |
| 317 | return field->description_->dataType; |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | GPB_INLINE int32_t GPBFieldHasIndex(GPBFieldDescriptor *field) { |
| 321 | return field->description_->hasIndex; |
| 322 | } |
| 323 | |
| 324 | GPB_INLINE uint32_t GPBFieldNumber(GPBFieldDescriptor *field) { |
| 325 | return field->description_->number; |
| 326 | } |
| 327 | |
Thomas Van Lenten | c8a440d | 2016-05-25 13:46:00 -0400 | [diff] [blame] | 328 | #pragma clang diagnostic pop |
| 329 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 330 | uint32_t GPBFieldTag(GPBFieldDescriptor *self); |
| 331 | |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 332 | // For repeated fields, alternateWireType is the wireType with the opposite |
| 333 | // value for the packable property. i.e. - if the field was marked packed it |
| 334 | // would be the wire type for unpacked; if the field was marked unpacked, it |
| 335 | // would be the wire type for packed. |
| 336 | uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self); |
| 337 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 338 | GPB_INLINE BOOL GPBHasPreservingUnknownEnumSemantics(GPBFileSyntax syntax) { |
| 339 | return syntax == GPBFileSyntaxProto3; |
| 340 | } |
| 341 | |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 342 | GPB_INLINE BOOL GPBExtensionIsRepeated(GPBExtensionDescription *description) { |
| 343 | return (description->options & GPBExtensionRepeated) != 0; |
| 344 | } |
| 345 | |
| 346 | GPB_INLINE BOOL GPBExtensionIsPacked(GPBExtensionDescription *description) { |
| 347 | return (description->options & GPBExtensionPacked) != 0; |
| 348 | } |
| 349 | |
| 350 | GPB_INLINE BOOL GPBExtensionIsWireFormat(GPBExtensionDescription *description) { |
| 351 | return (description->options & GPBExtensionSetWireFormat) != 0; |
| 352 | } |
| 353 | |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 354 | // Helper for compile time assets. |
Thomas Van Lenten | c8a440d | 2016-05-25 13:46:00 -0400 | [diff] [blame] | 355 | #ifndef GPBInternalCompileAssert |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 356 | #if __has_feature(c_static_assert) || __has_extension(c_static_assert) |
Thomas Van Lenten | c8a440d | 2016-05-25 13:46:00 -0400 | [diff] [blame] | 357 | #define GPBInternalCompileAssert(test, msg) _Static_assert((test), #msg) |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 358 | #else |
| 359 | // Pre-Xcode 7 support. |
Thomas Van Lenten | c8a440d | 2016-05-25 13:46:00 -0400 | [diff] [blame] | 360 | #define GPBInternalCompileAssertSymbolInner(line, msg) GPBInternalCompileAssert ## line ## __ ## msg |
| 361 | #define GPBInternalCompileAssertSymbol(line, msg) GPBInternalCompileAssertSymbolInner(line, msg) |
| 362 | #define GPBInternalCompileAssert(test, msg) \ |
| 363 | typedef char GPBInternalCompileAssertSymbol(__LINE__, msg) [ ((test) ? 1 : -1) ] |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 364 | #endif // __has_feature(c_static_assert) || __has_extension(c_static_assert) |
Thomas Van Lenten | c8a440d | 2016-05-25 13:46:00 -0400 | [diff] [blame] | 365 | #endif // GPBInternalCompileAssert |
Thomas Van Lenten | 79a23c4 | 2016-03-17 10:04:21 -0400 | [diff] [blame] | 366 | |
| 367 | // Sanity check that there isn't padding between the field description |
| 368 | // structures with and without a default. |
Thomas Van Lenten | c8a440d | 2016-05-25 13:46:00 -0400 | [diff] [blame] | 369 | GPBInternalCompileAssert(sizeof(GPBMessageFieldDescriptionWithDefault) == |
| 370 | (sizeof(GPBGenericValue) + |
| 371 | sizeof(GPBMessageFieldDescription)), |
| 372 | DescriptionsWithDefault_different_size_than_expected); |
Thomas Van Lenten | d846b0b | 2015-06-08 16:24:57 -0400 | [diff] [blame] | 373 | |
Thomas Van Lenten | 30650d8 | 2015-05-01 08:57:16 -0400 | [diff] [blame] | 374 | CF_EXTERN_C_END |