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#import <Foundation/Foundation.h>
32ffe3c632Sopenharmony_ci
33ffe3c632Sopenharmony_ci#import "GPBRuntimeTypes.h"
34ffe3c632Sopenharmony_ci
35ffe3c632Sopenharmony_ci@class GPBEnumDescriptor;
36ffe3c632Sopenharmony_ci@class GPBFieldDescriptor;
37ffe3c632Sopenharmony_ci@class GPBFileDescriptor;
38ffe3c632Sopenharmony_ci@class GPBOneofDescriptor;
39ffe3c632Sopenharmony_ci
40ffe3c632Sopenharmony_ciNS_ASSUME_NONNULL_BEGIN
41ffe3c632Sopenharmony_ci
42ffe3c632Sopenharmony_ci/** Syntax used in the proto file. */
43ffe3c632Sopenharmony_citypedef NS_ENUM(uint8_t, GPBFileSyntax) {
44ffe3c632Sopenharmony_ci  /** Unknown syntax. */
45ffe3c632Sopenharmony_ci  GPBFileSyntaxUnknown = 0,
46ffe3c632Sopenharmony_ci  /** Proto2 syntax. */
47ffe3c632Sopenharmony_ci  GPBFileSyntaxProto2 = 2,
48ffe3c632Sopenharmony_ci  /** Proto3 syntax. */
49ffe3c632Sopenharmony_ci  GPBFileSyntaxProto3 = 3,
50ffe3c632Sopenharmony_ci};
51ffe3c632Sopenharmony_ci
52ffe3c632Sopenharmony_ci/** Type of proto field. */
53ffe3c632Sopenharmony_citypedef NS_ENUM(uint8_t, GPBFieldType) {
54ffe3c632Sopenharmony_ci  /** Optional/required field. Only valid for proto2 fields. */
55ffe3c632Sopenharmony_ci  GPBFieldTypeSingle,
56ffe3c632Sopenharmony_ci  /** Repeated field. */
57ffe3c632Sopenharmony_ci  GPBFieldTypeRepeated,
58ffe3c632Sopenharmony_ci  /** Map field. */
59ffe3c632Sopenharmony_ci  GPBFieldTypeMap,
60ffe3c632Sopenharmony_ci};
61ffe3c632Sopenharmony_ci
62ffe3c632Sopenharmony_ci/**
63ffe3c632Sopenharmony_ci * Describes a proto message.
64ffe3c632Sopenharmony_ci **/
65ffe3c632Sopenharmony_ci@interface GPBDescriptor : NSObject<NSCopying>
66ffe3c632Sopenharmony_ci
67ffe3c632Sopenharmony_ci/** Name of the message. */
68ffe3c632Sopenharmony_ci@property(nonatomic, readonly, copy) NSString *name;
69ffe3c632Sopenharmony_ci/** Fields declared in the message. */
70ffe3c632Sopenharmony_ci@property(nonatomic, readonly, strong, nullable) NSArray<GPBFieldDescriptor*> *fields;
71ffe3c632Sopenharmony_ci/** Oneofs declared in the message. */
72ffe3c632Sopenharmony_ci@property(nonatomic, readonly, strong, nullable) NSArray<GPBOneofDescriptor*> *oneofs;
73ffe3c632Sopenharmony_ci/** Extension range declared for the message. */
74ffe3c632Sopenharmony_ci@property(nonatomic, readonly, nullable) const GPBExtensionRange *extensionRanges;
75ffe3c632Sopenharmony_ci/** Number of extension ranges declared for the message. */
76ffe3c632Sopenharmony_ci@property(nonatomic, readonly) uint32_t extensionRangesCount;
77ffe3c632Sopenharmony_ci/** Descriptor for the file where the message was defined. */
78ffe3c632Sopenharmony_ci@property(nonatomic, readonly) GPBFileDescriptor *file;
79ffe3c632Sopenharmony_ci
80ffe3c632Sopenharmony_ci/** Whether the message is in wire format or not. */
81ffe3c632Sopenharmony_ci@property(nonatomic, readonly, getter=isWireFormat) BOOL wireFormat;
82ffe3c632Sopenharmony_ci/** The class of this message. */
83ffe3c632Sopenharmony_ci@property(nonatomic, readonly) Class messageClass;
84ffe3c632Sopenharmony_ci/** Containing message descriptor if this message is nested, or nil otherwise. */
85ffe3c632Sopenharmony_ci@property(readonly, nullable) GPBDescriptor *containingType;
86ffe3c632Sopenharmony_ci/**
87ffe3c632Sopenharmony_ci * Fully qualified name for this message (package.message). Can be nil if the
88ffe3c632Sopenharmony_ci * value is unable to be computed.
89ffe3c632Sopenharmony_ci */
90ffe3c632Sopenharmony_ci@property(readonly, nullable) NSString *fullName;
91ffe3c632Sopenharmony_ci
92ffe3c632Sopenharmony_ci/**
93ffe3c632Sopenharmony_ci * Gets the field for the given number.
94ffe3c632Sopenharmony_ci *
95ffe3c632Sopenharmony_ci * @param fieldNumber The number for the field to get.
96ffe3c632Sopenharmony_ci *
97ffe3c632Sopenharmony_ci * @return The field descriptor for the given number, or nil if not found.
98ffe3c632Sopenharmony_ci **/
99ffe3c632Sopenharmony_ci- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
100ffe3c632Sopenharmony_ci
101ffe3c632Sopenharmony_ci/**
102ffe3c632Sopenharmony_ci * Gets the field for the given name.
103ffe3c632Sopenharmony_ci *
104ffe3c632Sopenharmony_ci * @param name The name for the field to get.
105ffe3c632Sopenharmony_ci *
106ffe3c632Sopenharmony_ci * @return The field descriptor for the given name, or nil if not found.
107ffe3c632Sopenharmony_ci **/
108ffe3c632Sopenharmony_ci- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
109ffe3c632Sopenharmony_ci
110ffe3c632Sopenharmony_ci/**
111ffe3c632Sopenharmony_ci * Gets the oneof for the given name.
112ffe3c632Sopenharmony_ci *
113ffe3c632Sopenharmony_ci * @param name The name for the oneof to get.
114ffe3c632Sopenharmony_ci *
115ffe3c632Sopenharmony_ci * @return The oneof descriptor for the given name, or nil if not found.
116ffe3c632Sopenharmony_ci **/
117ffe3c632Sopenharmony_ci- (nullable GPBOneofDescriptor *)oneofWithName:(NSString *)name;
118ffe3c632Sopenharmony_ci
119ffe3c632Sopenharmony_ci@end
120ffe3c632Sopenharmony_ci
121ffe3c632Sopenharmony_ci/**
122ffe3c632Sopenharmony_ci * Describes a proto file.
123ffe3c632Sopenharmony_ci **/
124ffe3c632Sopenharmony_ci@interface GPBFileDescriptor : NSObject
125ffe3c632Sopenharmony_ci
126ffe3c632Sopenharmony_ci/** The package declared in the proto file. */
127ffe3c632Sopenharmony_ci@property(nonatomic, readonly, copy) NSString *package;
128ffe3c632Sopenharmony_ci/** The objc prefix declared in the proto file. */
129ffe3c632Sopenharmony_ci@property(nonatomic, readonly, copy, nullable) NSString *objcPrefix;
130ffe3c632Sopenharmony_ci/** The syntax of the proto file. */
131ffe3c632Sopenharmony_ci@property(nonatomic, readonly) GPBFileSyntax syntax;
132ffe3c632Sopenharmony_ci
133ffe3c632Sopenharmony_ci@end
134ffe3c632Sopenharmony_ci
135ffe3c632Sopenharmony_ci/**
136ffe3c632Sopenharmony_ci * Describes a oneof field.
137ffe3c632Sopenharmony_ci **/
138ffe3c632Sopenharmony_ci@interface GPBOneofDescriptor : NSObject
139ffe3c632Sopenharmony_ci/** Name of the oneof field. */
140ffe3c632Sopenharmony_ci@property(nonatomic, readonly) NSString *name;
141ffe3c632Sopenharmony_ci/** Fields declared in the oneof. */
142ffe3c632Sopenharmony_ci@property(nonatomic, readonly) NSArray<GPBFieldDescriptor*> *fields;
143ffe3c632Sopenharmony_ci
144ffe3c632Sopenharmony_ci/**
145ffe3c632Sopenharmony_ci * Gets the field for the given number.
146ffe3c632Sopenharmony_ci *
147ffe3c632Sopenharmony_ci * @param fieldNumber The number for the field to get.
148ffe3c632Sopenharmony_ci *
149ffe3c632Sopenharmony_ci * @return The field descriptor for the given number, or nil if not found.
150ffe3c632Sopenharmony_ci **/
151ffe3c632Sopenharmony_ci- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
152ffe3c632Sopenharmony_ci
153ffe3c632Sopenharmony_ci/**
154ffe3c632Sopenharmony_ci * Gets the field for the given name.
155ffe3c632Sopenharmony_ci *
156ffe3c632Sopenharmony_ci * @param name The name for the field to get.
157ffe3c632Sopenharmony_ci *
158ffe3c632Sopenharmony_ci * @return The field descriptor for the given name, or nil if not found.
159ffe3c632Sopenharmony_ci **/
160ffe3c632Sopenharmony_ci- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
161ffe3c632Sopenharmony_ci
162ffe3c632Sopenharmony_ci@end
163ffe3c632Sopenharmony_ci
164ffe3c632Sopenharmony_ci/**
165ffe3c632Sopenharmony_ci * Describes a proto field.
166ffe3c632Sopenharmony_ci **/
167ffe3c632Sopenharmony_ci@interface GPBFieldDescriptor : NSObject
168ffe3c632Sopenharmony_ci
169ffe3c632Sopenharmony_ci/** Name of the field. */
170ffe3c632Sopenharmony_ci@property(nonatomic, readonly, copy) NSString *name;
171ffe3c632Sopenharmony_ci/** Number associated with the field. */
172ffe3c632Sopenharmony_ci@property(nonatomic, readonly) uint32_t number;
173ffe3c632Sopenharmony_ci/** Data type contained in the field. */
174ffe3c632Sopenharmony_ci@property(nonatomic, readonly) GPBDataType dataType;
175ffe3c632Sopenharmony_ci/** Whether it has a default value or not. */
176ffe3c632Sopenharmony_ci@property(nonatomic, readonly) BOOL hasDefaultValue;
177ffe3c632Sopenharmony_ci/** Default value for the field. */
178ffe3c632Sopenharmony_ci@property(nonatomic, readonly) GPBGenericValue defaultValue;
179ffe3c632Sopenharmony_ci/** Whether this field is required. Only valid for proto2 fields. */
180ffe3c632Sopenharmony_ci@property(nonatomic, readonly, getter=isRequired) BOOL required;
181ffe3c632Sopenharmony_ci/** Whether this field is optional. */
182ffe3c632Sopenharmony_ci@property(nonatomic, readonly, getter=isOptional) BOOL optional;
183ffe3c632Sopenharmony_ci/** Type of field (single, repeated, map). */
184ffe3c632Sopenharmony_ci@property(nonatomic, readonly) GPBFieldType fieldType;
185ffe3c632Sopenharmony_ci/** Type of the key if the field is a map. The value's type is -fieldType. */
186ffe3c632Sopenharmony_ci@property(nonatomic, readonly) GPBDataType mapKeyDataType;
187ffe3c632Sopenharmony_ci/** Whether the field is packable. */
188ffe3c632Sopenharmony_ci@property(nonatomic, readonly, getter=isPackable) BOOL packable;
189ffe3c632Sopenharmony_ci
190ffe3c632Sopenharmony_ci/** The containing oneof if this field is part of one, nil otherwise. */
191ffe3c632Sopenharmony_ci@property(nonatomic, readonly, nullable) GPBOneofDescriptor *containingOneof;
192ffe3c632Sopenharmony_ci
193ffe3c632Sopenharmony_ci/** Class of the message if the field is of message type. */
194ffe3c632Sopenharmony_ci@property(nonatomic, readonly, nullable) Class msgClass;
195ffe3c632Sopenharmony_ci
196ffe3c632Sopenharmony_ci/** Descriptor for the enum if this field is an enum. */
197ffe3c632Sopenharmony_ci@property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor;
198ffe3c632Sopenharmony_ci
199ffe3c632Sopenharmony_ci/**
200ffe3c632Sopenharmony_ci * Checks whether the given enum raw value is a valid enum value.
201ffe3c632Sopenharmony_ci *
202ffe3c632Sopenharmony_ci * @param value The raw enum value to check.
203ffe3c632Sopenharmony_ci *
204ffe3c632Sopenharmony_ci * @return YES if value is a valid enum raw value.
205ffe3c632Sopenharmony_ci **/
206ffe3c632Sopenharmony_ci- (BOOL)isValidEnumValue:(int32_t)value;
207ffe3c632Sopenharmony_ci
208ffe3c632Sopenharmony_ci/** @return Name for the text format, or nil if not known. */
209ffe3c632Sopenharmony_ci- (nullable NSString *)textFormatName;
210ffe3c632Sopenharmony_ci
211ffe3c632Sopenharmony_ci@end
212ffe3c632Sopenharmony_ci
213ffe3c632Sopenharmony_ci/**
214ffe3c632Sopenharmony_ci * Describes a proto enum.
215ffe3c632Sopenharmony_ci **/
216ffe3c632Sopenharmony_ci@interface GPBEnumDescriptor : NSObject
217ffe3c632Sopenharmony_ci
218ffe3c632Sopenharmony_ci/** Name of the enum. */
219ffe3c632Sopenharmony_ci@property(nonatomic, readonly, copy) NSString *name;
220ffe3c632Sopenharmony_ci/** Function that validates that raw values are valid enum values. */
221ffe3c632Sopenharmony_ci@property(nonatomic, readonly) GPBEnumValidationFunc enumVerifier;
222ffe3c632Sopenharmony_ci
223ffe3c632Sopenharmony_ci/**
224ffe3c632Sopenharmony_ci * Returns the enum value name for the given raw enum.
225ffe3c632Sopenharmony_ci *
226ffe3c632Sopenharmony_ci * Note that there can be more than one name corresponding to a given value
227ffe3c632Sopenharmony_ci * if the allow_alias option is used.
228ffe3c632Sopenharmony_ci *
229ffe3c632Sopenharmony_ci * @param number The raw enum value.
230ffe3c632Sopenharmony_ci *
231ffe3c632Sopenharmony_ci * @return The first name that matches the enum value passed, or nil if not valid.
232ffe3c632Sopenharmony_ci **/
233ffe3c632Sopenharmony_ci- (nullable NSString *)enumNameForValue:(int32_t)number;
234ffe3c632Sopenharmony_ci
235ffe3c632Sopenharmony_ci/**
236ffe3c632Sopenharmony_ci * Gets the enum raw value for the given enum name.
237ffe3c632Sopenharmony_ci *
238ffe3c632Sopenharmony_ci * @param outValue A pointer where the value will be set.
239ffe3c632Sopenharmony_ci * @param name     The enum name for which to get the raw value.
240ffe3c632Sopenharmony_ci *
241ffe3c632Sopenharmony_ci * @return YES if a value was copied into the pointer, NO otherwise.
242ffe3c632Sopenharmony_ci **/
243ffe3c632Sopenharmony_ci- (BOOL)getValue:(nullable int32_t *)outValue forEnumName:(NSString *)name;
244ffe3c632Sopenharmony_ci
245ffe3c632Sopenharmony_ci/**
246ffe3c632Sopenharmony_ci * Returns the text format for the given raw enum value.
247ffe3c632Sopenharmony_ci *
248ffe3c632Sopenharmony_ci * @param number The raw enum value.
249ffe3c632Sopenharmony_ci *
250ffe3c632Sopenharmony_ci * @return The first text format name which matches the enum value, or nil if not valid.
251ffe3c632Sopenharmony_ci **/
252ffe3c632Sopenharmony_ci- (nullable NSString *)textFormatNameForValue:(int32_t)number;
253ffe3c632Sopenharmony_ci
254ffe3c632Sopenharmony_ci/**
255ffe3c632Sopenharmony_ci * Gets the enum raw value for the given text format name.
256ffe3c632Sopenharmony_ci *
257ffe3c632Sopenharmony_ci * @param outValue       A pointer where the value will be set.
258ffe3c632Sopenharmony_ci * @param textFormatName The text format name for which to get the raw value.
259ffe3c632Sopenharmony_ci *
260ffe3c632Sopenharmony_ci * @return YES if a value was copied into the pointer, NO otherwise.
261ffe3c632Sopenharmony_ci **/
262ffe3c632Sopenharmony_ci- (BOOL)getValue:(nullable int32_t *)outValue forEnumTextFormatName:(NSString *)textFormatName;
263ffe3c632Sopenharmony_ci
264ffe3c632Sopenharmony_ci/**
265ffe3c632Sopenharmony_ci * Gets the number of defined enum names.
266ffe3c632Sopenharmony_ci *
267ffe3c632Sopenharmony_ci * @return Count of the number of enum names, including any aliases.
268ffe3c632Sopenharmony_ci */
269ffe3c632Sopenharmony_ci@property(nonatomic, readonly) uint32_t enumNameCount;
270ffe3c632Sopenharmony_ci
271ffe3c632Sopenharmony_ci/**
272ffe3c632Sopenharmony_ci * Gets the enum name corresponding to the given index.
273ffe3c632Sopenharmony_ci *
274ffe3c632Sopenharmony_ci * @param index Index into the available names.  The defined range is from 0
275ffe3c632Sopenharmony_ci *              to self.enumNameCount - 1.
276ffe3c632Sopenharmony_ci *
277ffe3c632Sopenharmony_ci * @returns The enum name at the given index, or nil if the index is out of range.
278ffe3c632Sopenharmony_ci */
279ffe3c632Sopenharmony_ci- (nullable NSString *)getEnumNameForIndex:(uint32_t)index;
280ffe3c632Sopenharmony_ci
281ffe3c632Sopenharmony_ci/**
282ffe3c632Sopenharmony_ci * Gets the enum text format name corresponding to the given index.
283ffe3c632Sopenharmony_ci *
284ffe3c632Sopenharmony_ci * @param index Index into the available names.  The defined range is from 0
285ffe3c632Sopenharmony_ci *              to self.enumNameCount - 1.
286ffe3c632Sopenharmony_ci *
287ffe3c632Sopenharmony_ci * @returns The text format name at the given index, or nil if the index is out of range.
288ffe3c632Sopenharmony_ci */
289ffe3c632Sopenharmony_ci- (nullable NSString *)getEnumTextFormatNameForIndex:(uint32_t)index;
290ffe3c632Sopenharmony_ci
291ffe3c632Sopenharmony_ci@end
292ffe3c632Sopenharmony_ci
293ffe3c632Sopenharmony_ci/**
294ffe3c632Sopenharmony_ci * Describes a proto extension.
295ffe3c632Sopenharmony_ci **/
296ffe3c632Sopenharmony_ci@interface GPBExtensionDescriptor : NSObject<NSCopying>
297ffe3c632Sopenharmony_ci/** Field number under which the extension is stored. */
298ffe3c632Sopenharmony_ci@property(nonatomic, readonly) uint32_t fieldNumber;
299ffe3c632Sopenharmony_ci/** The containing message class, i.e. the class extended by this extension. */
300ffe3c632Sopenharmony_ci@property(nonatomic, readonly) Class containingMessageClass;
301ffe3c632Sopenharmony_ci/** Data type contained in the extension. */
302ffe3c632Sopenharmony_ci@property(nonatomic, readonly) GPBDataType dataType;
303ffe3c632Sopenharmony_ci/** Whether the extension is repeated. */
304ffe3c632Sopenharmony_ci@property(nonatomic, readonly, getter=isRepeated) BOOL repeated;
305ffe3c632Sopenharmony_ci/** Whether the extension is packable. */
306ffe3c632Sopenharmony_ci@property(nonatomic, readonly, getter=isPackable) BOOL packable;
307ffe3c632Sopenharmony_ci/** The class of the message if the extension is of message type. */
308ffe3c632Sopenharmony_ci@property(nonatomic, readonly) Class msgClass;
309ffe3c632Sopenharmony_ci/** The singleton name for the extension. */
310ffe3c632Sopenharmony_ci@property(nonatomic, readonly) NSString *singletonName;
311ffe3c632Sopenharmony_ci/** The enum descriptor if the extension is of enum type. */
312ffe3c632Sopenharmony_ci@property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor;
313ffe3c632Sopenharmony_ci/** The default value for the extension. */
314ffe3c632Sopenharmony_ci@property(nonatomic, readonly, nullable) id defaultValue;
315ffe3c632Sopenharmony_ci
316ffe3c632Sopenharmony_ci@end
317ffe3c632Sopenharmony_ci
318ffe3c632Sopenharmony_ciNS_ASSUME_NONNULL_END
319