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