blob: 651f4de08f980989e98ab25547a6029243cc2a78 [file] [log] [blame]
Brian Silverman9c614bc2016-02-15 20:20:02 -05001// 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#import <Foundation/Foundation.h>
32
33#import "GPBRuntimeTypes.h"
34
35@class GPBEnumDescriptor;
36@class GPBFieldDescriptor;
Brian Silverman9c614bc2016-02-15 20:20:02 -050037@class GPBFileDescriptor;
38@class GPBOneofDescriptor;
39
40NS_ASSUME_NONNULL_BEGIN
41
Austin Schuh40c16522018-10-28 20:27:54 -070042/** Syntax used in the proto file. */
43typedef NS_ENUM(uint8_t, GPBFileSyntax) {
44 /** Unknown syntax. */
Brian Silverman9c614bc2016-02-15 20:20:02 -050045 GPBFileSyntaxUnknown = 0,
Austin Schuh40c16522018-10-28 20:27:54 -070046 /** Proto2 syntax. */
Brian Silverman9c614bc2016-02-15 20:20:02 -050047 GPBFileSyntaxProto2 = 2,
Austin Schuh40c16522018-10-28 20:27:54 -070048 /** Proto3 syntax. */
Brian Silverman9c614bc2016-02-15 20:20:02 -050049 GPBFileSyntaxProto3 = 3,
50};
51
Austin Schuh40c16522018-10-28 20:27:54 -070052/** Type of proto field. */
53typedef NS_ENUM(uint8_t, GPBFieldType) {
54 /** Optional/required field. Only valid for proto2 fields. */
55 GPBFieldTypeSingle,
56 /** Repeated field. */
57 GPBFieldTypeRepeated,
58 /** Map field. */
59 GPBFieldTypeMap,
Brian Silverman9c614bc2016-02-15 20:20:02 -050060};
61
Austin Schuh40c16522018-10-28 20:27:54 -070062/**
63 * Describes a proto message.
64 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -050065@interface GPBDescriptor : NSObject<NSCopying>
66
Austin Schuh40c16522018-10-28 20:27:54 -070067/** Name of the message. */
Brian Silverman9c614bc2016-02-15 20:20:02 -050068@property(nonatomic, readonly, copy) NSString *name;
Austin Schuh40c16522018-10-28 20:27:54 -070069/** Fields declared in the message. */
70@property(nonatomic, readonly, strong, nullable) NSArray<GPBFieldDescriptor*> *fields;
71/** Oneofs declared in the message. */
72@property(nonatomic, readonly, strong, nullable) NSArray<GPBOneofDescriptor*> *oneofs;
73/** Extension range declared for the message. */
Brian Silverman9c614bc2016-02-15 20:20:02 -050074@property(nonatomic, readonly, nullable) const GPBExtensionRange *extensionRanges;
Austin Schuh40c16522018-10-28 20:27:54 -070075/** Number of extension ranges declared for the message. */
76@property(nonatomic, readonly) uint32_t extensionRangesCount;
77/** Descriptor for the file where the message was defined. */
Brian Silverman9c614bc2016-02-15 20:20:02 -050078@property(nonatomic, readonly, assign) GPBFileDescriptor *file;
79
Austin Schuh40c16522018-10-28 20:27:54 -070080/** Whether the message is in wire format or not. */
Brian Silverman9c614bc2016-02-15 20:20:02 -050081@property(nonatomic, readonly, getter=isWireFormat) BOOL wireFormat;
Austin Schuh40c16522018-10-28 20:27:54 -070082/** The class of this message. */
Brian Silverman9c614bc2016-02-15 20:20:02 -050083@property(nonatomic, readonly) Class messageClass;
Austin Schuh40c16522018-10-28 20:27:54 -070084/** Containing message descriptor if this message is nested, or nil otherwise. */
85@property(readonly, nullable) GPBDescriptor *containingType;
86/**
87 * Fully qualified name for this message (package.message). Can be nil if the
88 * value is unable to be computed.
89 */
90@property(readonly, nullable) NSString *fullName;
Brian Silverman9c614bc2016-02-15 20:20:02 -050091
Austin Schuh40c16522018-10-28 20:27:54 -070092/**
93 * Gets the field for the given number.
94 *
95 * @param fieldNumber The number for the field to get.
96 *
97 * @return The field descriptor for the given number, or nil if not found.
98 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -050099- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
Austin Schuh40c16522018-10-28 20:27:54 -0700100
101/**
102 * Gets the field for the given name.
103 *
104 * @param name The name for the field to get.
105 *
106 * @return The field descriptor for the given name, or nil if not found.
107 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500108- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
Austin Schuh40c16522018-10-28 20:27:54 -0700109
110/**
111 * Gets the oneof for the given name.
112 *
113 * @param name The name for the oneof to get.
114 *
115 * @return The oneof descriptor for the given name, or nil if not found.
116 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500117- (nullable GPBOneofDescriptor *)oneofWithName:(NSString *)name;
Brian Silverman9c614bc2016-02-15 20:20:02 -0500118
119@end
120
Austin Schuh40c16522018-10-28 20:27:54 -0700121/**
122 * Describes a proto file.
123 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500124@interface GPBFileDescriptor : NSObject
125
Austin Schuh40c16522018-10-28 20:27:54 -0700126/** The package declared in the proto file. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500127@property(nonatomic, readonly, copy) NSString *package;
Austin Schuh40c16522018-10-28 20:27:54 -0700128/** The objc prefix declared in the proto file. */
129@property(nonatomic, readonly, copy, nullable) NSString *objcPrefix;
130/** The syntax of the proto file. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500131@property(nonatomic, readonly) GPBFileSyntax syntax;
132
133@end
134
Austin Schuh40c16522018-10-28 20:27:54 -0700135/**
136 * Describes a oneof field.
137 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500138@interface GPBOneofDescriptor : NSObject
Austin Schuh40c16522018-10-28 20:27:54 -0700139/** Name of the oneof field. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500140@property(nonatomic, readonly) NSString *name;
Austin Schuh40c16522018-10-28 20:27:54 -0700141/** Fields declared in the oneof. */
142@property(nonatomic, readonly) NSArray<GPBFieldDescriptor*> *fields;
Brian Silverman9c614bc2016-02-15 20:20:02 -0500143
Austin Schuh40c16522018-10-28 20:27:54 -0700144/**
145 * Gets the field for the given number.
146 *
147 * @param fieldNumber The number for the field to get.
148 *
149 * @return The field descriptor for the given number, or nil if not found.
150 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500151- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
Austin Schuh40c16522018-10-28 20:27:54 -0700152
153/**
154 * Gets the field for the given name.
155 *
156 * @param name The name for the field to get.
157 *
158 * @return The field descriptor for the given name, or nil if not found.
159 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500160- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
Austin Schuh40c16522018-10-28 20:27:54 -0700161
Brian Silverman9c614bc2016-02-15 20:20:02 -0500162@end
163
Austin Schuh40c16522018-10-28 20:27:54 -0700164/**
165 * Describes a proto field.
166 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500167@interface GPBFieldDescriptor : NSObject
168
Austin Schuh40c16522018-10-28 20:27:54 -0700169/** Name of the field. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500170@property(nonatomic, readonly, copy) NSString *name;
Austin Schuh40c16522018-10-28 20:27:54 -0700171/** Number associated with the field. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500172@property(nonatomic, readonly) uint32_t number;
Austin Schuh40c16522018-10-28 20:27:54 -0700173/** Data type contained in the field. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500174@property(nonatomic, readonly) GPBDataType dataType;
Austin Schuh40c16522018-10-28 20:27:54 -0700175/** Whether it has a default value or not. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500176@property(nonatomic, readonly) BOOL hasDefaultValue;
Austin Schuh40c16522018-10-28 20:27:54 -0700177/** Default value for the field. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500178@property(nonatomic, readonly) GPBGenericValue defaultValue;
Austin Schuh40c16522018-10-28 20:27:54 -0700179/** Whether this field is required. Only valid for proto2 fields. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500180@property(nonatomic, readonly, getter=isRequired) BOOL required;
Austin Schuh40c16522018-10-28 20:27:54 -0700181/** Whether this field is optional. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500182@property(nonatomic, readonly, getter=isOptional) BOOL optional;
Austin Schuh40c16522018-10-28 20:27:54 -0700183/** Type of field (single, repeated, map). */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500184@property(nonatomic, readonly) GPBFieldType fieldType;
Austin Schuh40c16522018-10-28 20:27:54 -0700185/** Type of the key if the field is a map. The value's type is -fieldType. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500186@property(nonatomic, readonly) GPBDataType mapKeyDataType;
Austin Schuh40c16522018-10-28 20:27:54 -0700187/** Whether the field is packable. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500188@property(nonatomic, readonly, getter=isPackable) BOOL packable;
189
Austin Schuh40c16522018-10-28 20:27:54 -0700190/** The containing oneof if this field is part of one, nil otherwise. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500191@property(nonatomic, readonly, assign, nullable) GPBOneofDescriptor *containingOneof;
192
Austin Schuh40c16522018-10-28 20:27:54 -0700193/** Class of the message if the field is of message type. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500194@property(nonatomic, readonly, assign, nullable) Class msgClass;
195
Austin Schuh40c16522018-10-28 20:27:54 -0700196/** Descriptor for the enum if this field is an enum. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500197@property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor;
198
Austin Schuh40c16522018-10-28 20:27:54 -0700199/**
200 * Checks whether the given enum raw value is a valid enum value.
201 *
202 * @param value The raw enum value to check.
203 *
204 * @return YES if value is a valid enum raw value.
205 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500206- (BOOL)isValidEnumValue:(int32_t)value;
207
Austin Schuh40c16522018-10-28 20:27:54 -0700208/** @return Name for the text format, or nil if not known. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500209- (nullable NSString *)textFormatName;
210
211@end
212
Austin Schuh40c16522018-10-28 20:27:54 -0700213/**
214 * Describes a proto enum.
215 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500216@interface GPBEnumDescriptor : NSObject
217
Austin Schuh40c16522018-10-28 20:27:54 -0700218/** Name of the enum. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500219@property(nonatomic, readonly, copy) NSString *name;
Austin Schuh40c16522018-10-28 20:27:54 -0700220/** Function that validates that raw values are valid enum values. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500221@property(nonatomic, readonly) GPBEnumValidationFunc enumVerifier;
222
Austin Schuh40c16522018-10-28 20:27:54 -0700223/**
224 * Returns the enum value name for the given raw enum.
225 *
226 * @param number The raw enum value.
227 *
228 * @return The name of the enum value passed, or nil if not valid.
229 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500230- (nullable NSString *)enumNameForValue:(int32_t)number;
Austin Schuh40c16522018-10-28 20:27:54 -0700231
232/**
233 * Gets the enum raw value for the given enum name.
234 *
235 * @param outValue A pointer where the value will be set.
236 * @param name The enum name for which to get the raw value.
237 *
238 * @return YES if a value was copied into the pointer, NO otherwise.
239 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500240- (BOOL)getValue:(nullable int32_t *)outValue forEnumName:(NSString *)name;
241
Austin Schuh40c16522018-10-28 20:27:54 -0700242/**
243 * Returns the text format for the given raw enum value.
244 *
245 * @param number The raw enum value.
246 *
247 * @return The text format name for the raw enum value, or nil if not valid.
248 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500249- (nullable NSString *)textFormatNameForValue:(int32_t)number;
250
Austin Schuh40c16522018-10-28 20:27:54 -0700251/**
252 * Gets the enum raw value for the given text format name.
253 *
254 * @param outValue A pointer where the value will be set.
255 * @param textFormatName The text format name for which to get the raw value.
256 *
257 * @return YES if a value was copied into the pointer, NO otherwise.
258 **/
259- (BOOL)getValue:(nullable int32_t *)outValue forEnumTextFormatName:(NSString *)textFormatName;
260
Brian Silverman9c614bc2016-02-15 20:20:02 -0500261@end
262
Austin Schuh40c16522018-10-28 20:27:54 -0700263/**
264 * Describes a proto extension.
265 **/
Brian Silverman9c614bc2016-02-15 20:20:02 -0500266@interface GPBExtensionDescriptor : NSObject<NSCopying>
Austin Schuh40c16522018-10-28 20:27:54 -0700267/** Field number under which the extension is stored. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500268@property(nonatomic, readonly) uint32_t fieldNumber;
Austin Schuh40c16522018-10-28 20:27:54 -0700269/** The containing message class, i.e. the class extended by this extension. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500270@property(nonatomic, readonly) Class containingMessageClass;
Austin Schuh40c16522018-10-28 20:27:54 -0700271/** Data type contained in the extension. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500272@property(nonatomic, readonly) GPBDataType dataType;
Austin Schuh40c16522018-10-28 20:27:54 -0700273/** Whether the extension is repeated. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500274@property(nonatomic, readonly, getter=isRepeated) BOOL repeated;
Austin Schuh40c16522018-10-28 20:27:54 -0700275/** Whether the extension is packable. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500276@property(nonatomic, readonly, getter=isPackable) BOOL packable;
Austin Schuh40c16522018-10-28 20:27:54 -0700277/** The class of the message if the extension is of message type. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500278@property(nonatomic, readonly, assign) Class msgClass;
Austin Schuh40c16522018-10-28 20:27:54 -0700279/** The singleton name for the extension. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500280@property(nonatomic, readonly) NSString *singletonName;
Austin Schuh40c16522018-10-28 20:27:54 -0700281/** The enum descriptor if the extension is of enum type. */
Brian Silverman9c614bc2016-02-15 20:20:02 -0500282@property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor;
Austin Schuh40c16522018-10-28 20:27:54 -0700283/** The default value for the extension. */
284@property(nonatomic, readonly, nullable) id defaultValue;
285
Brian Silverman9c614bc2016-02-15 20:20:02 -0500286@end
287
288NS_ASSUME_NONNULL_END