blob: a6eff0fb7d14b97eceb344f97d25d6fadb353160 [file] [log] [blame]
Thomas Van Lenten30650d82015-05-01 08:57:16 -04001// 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
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040033#import "GPBRuntimeTypes.h"
Thomas Van Lenten30650d82015-05-01 08:57:16 -040034
35@class GPBEnumDescriptor;
36@class GPBFieldDescriptor;
Thomas Van Lenten30650d82015-05-01 08:57:16 -040037@class GPBFileDescriptor;
38@class GPBOneofDescriptor;
39
Thomas Van Lenten8c889572015-06-16 16:45:14 -040040NS_ASSUME_NONNULL_BEGIN
41
Thomas Van Lenten79a23c42016-03-17 10:04:21 -040042typedef NS_ENUM(uint8_t, GPBFileSyntax) {
Thomas Van Lenten30650d82015-05-01 08:57:16 -040043 GPBFileSyntaxUnknown = 0,
44 GPBFileSyntaxProto2 = 2,
45 GPBFileSyntaxProto3 = 3,
46};
47
Thomas Van Lenten79a23c42016-03-17 10:04:21 -040048typedef NS_ENUM(uint8_t, GPBFieldType) {
Thomas Van Lenten30650d82015-05-01 08:57:16 -040049 GPBFieldTypeSingle, // optional/required
50 GPBFieldTypeRepeated, // repeated
51 GPBFieldTypeMap, // map<K,V>
52};
53
54@interface GPBDescriptor : NSObject<NSCopying>
55
56@property(nonatomic, readonly, copy) NSString *name;
Thomas Van Lenten2480acb2015-11-30 14:38:04 -050057@property(nonatomic, readonly, strong, nullable) NSArray<GPBFieldDescriptor*> *fields;
58@property(nonatomic, readonly, strong, nullable) NSArray<GPBOneofDescriptor*> *oneofs;
Thomas Van Lenten8c889572015-06-16 16:45:14 -040059@property(nonatomic, readonly, nullable) const GPBExtensionRange *extensionRanges;
Thomas Van Lenten79a23c42016-03-17 10:04:21 -040060@property(nonatomic, readonly) uint32_t extensionRangesCount;
Thomas Van Lenten30650d82015-05-01 08:57:16 -040061@property(nonatomic, readonly, assign) GPBFileDescriptor *file;
62
63@property(nonatomic, readonly, getter=isWireFormat) BOOL wireFormat;
64@property(nonatomic, readonly) Class messageClass;
65
Thomas Van Lenten8c889572015-06-16 16:45:14 -040066- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
67- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
68- (nullable GPBOneofDescriptor *)oneofWithName:(NSString *)name;
Thomas Van Lenten30650d82015-05-01 08:57:16 -040069
70@end
71
72@interface GPBFileDescriptor : NSObject
73
74@property(nonatomic, readonly, copy) NSString *package;
75@property(nonatomic, readonly) GPBFileSyntax syntax;
76
77@end
78
79@interface GPBOneofDescriptor : NSObject
80@property(nonatomic, readonly) NSString *name;
Thomas Van Lenten2480acb2015-11-30 14:38:04 -050081@property(nonatomic, readonly) NSArray<GPBFieldDescriptor*> *fields;
Thomas Van Lenten30650d82015-05-01 08:57:16 -040082
Thomas Van Lenten8c889572015-06-16 16:45:14 -040083- (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
84- (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name;
Thomas Van Lenten30650d82015-05-01 08:57:16 -040085@end
86
87@interface GPBFieldDescriptor : NSObject
88
89@property(nonatomic, readonly, copy) NSString *name;
90@property(nonatomic, readonly) uint32_t number;
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040091@property(nonatomic, readonly) GPBDataType dataType;
Thomas Van Lenten30650d82015-05-01 08:57:16 -040092@property(nonatomic, readonly) BOOL hasDefaultValue;
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040093@property(nonatomic, readonly) GPBGenericValue defaultValue;
Thomas Van Lenten30650d82015-05-01 08:57:16 -040094@property(nonatomic, readonly, getter=isRequired) BOOL required;
95@property(nonatomic, readonly, getter=isOptional) BOOL optional;
96@property(nonatomic, readonly) GPBFieldType fieldType;
97// If it is a map, the value type is in -type.
Thomas Van Lentend846b0b2015-06-08 16:24:57 -040098@property(nonatomic, readonly) GPBDataType mapKeyDataType;
Thomas Van Lenten30650d82015-05-01 08:57:16 -040099@property(nonatomic, readonly, getter=isPackable) BOOL packable;
100
Thomas Van Lenten8c889572015-06-16 16:45:14 -0400101@property(nonatomic, readonly, assign, nullable) GPBOneofDescriptor *containingOneof;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400102
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400103// Message properties
Thomas Van Lenten8c889572015-06-16 16:45:14 -0400104@property(nonatomic, readonly, assign, nullable) Class msgClass;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400105
106// Enum properties
Thomas Van Lenten8c889572015-06-16 16:45:14 -0400107@property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400108
109- (BOOL)isValidEnumValue:(int32_t)value;
110
111// For now, this will return nil if it doesn't know the name to use for
112// TextFormat.
Thomas Van Lenten8c889572015-06-16 16:45:14 -0400113- (nullable NSString *)textFormatName;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400114
115@end
116
117@interface GPBEnumDescriptor : NSObject
118
119@property(nonatomic, readonly, copy) NSString *name;
120@property(nonatomic, readonly) GPBEnumValidationFunc enumVerifier;
121
Thomas Van Lenten8c889572015-06-16 16:45:14 -0400122- (nullable NSString *)enumNameForValue:(int32_t)number;
123- (BOOL)getValue:(nullable int32_t *)outValue forEnumName:(NSString *)name;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400124
Thomas Van Lenten8c889572015-06-16 16:45:14 -0400125- (nullable NSString *)textFormatNameForValue:(int32_t)number;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400126
127@end
128
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400129@interface GPBExtensionDescriptor : NSObject<NSCopying>
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400130@property(nonatomic, readonly) uint32_t fieldNumber;
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400131@property(nonatomic, readonly) Class containingMessageClass;
132@property(nonatomic, readonly) GPBDataType dataType;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400133@property(nonatomic, readonly, getter=isRepeated) BOOL repeated;
134@property(nonatomic, readonly, getter=isPackable) BOOL packable;
135@property(nonatomic, readonly, assign) Class msgClass;
136@property(nonatomic, readonly) NSString *singletonName;
Thomas Van Lenten8c889572015-06-16 16:45:14 -0400137@property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor;
Thomas Van Lentend846b0b2015-06-08 16:24:57 -0400138@property(nonatomic, readonly) id defaultValue;
Thomas Van Lenten30650d82015-05-01 08:57:16 -0400139@end
Thomas Van Lenten8c889572015-06-16 16:45:14 -0400140
141NS_ASSUME_NONNULL_END