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 #import <Foundation/Foundation.h> 32 33 #import "GPBRuntimeTypes.h" 34 35 @class GPBEnumDescriptor; 36 @class GPBFieldDescriptor; 37 @class GPBFileDescriptor; 38 @class GPBOneofDescriptor; 39 40 NS_ASSUME_NONNULL_BEGIN 41 42 typedef NS_ENUM(uint8_t, GPBFileSyntax) { 43 GPBFileSyntaxUnknown = 0, 44 GPBFileSyntaxProto2 = 2, 45 GPBFileSyntaxProto3 = 3, 46 }; 47 48 typedef NS_ENUM(uint8_t, GPBFieldType) { 49 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; 57 @property(nonatomic, readonly, strong, nullable) NSArray<GPBFieldDescriptor*> *fields; 58 @property(nonatomic, readonly, strong, nullable) NSArray<GPBOneofDescriptor*> *oneofs; 59 @property(nonatomic, readonly, nullable) const GPBExtensionRange *extensionRanges; 60 @property(nonatomic, readonly) uint32_t extensionRangesCount; 61 @property(nonatomic, readonly, assign) GPBFileDescriptor *file; 62 63 @property(nonatomic, readonly, getter=isWireFormat) BOOL wireFormat; 64 @property(nonatomic, readonly) Class messageClass; 65 66 - (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber; 67 - (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name; 68 - (nullable GPBOneofDescriptor *)oneofWithName:(NSString *)name; 69 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; 81 @property(nonatomic, readonly) NSArray<GPBFieldDescriptor*> *fields; 82 83 - (nullable GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber; 84 - (nullable GPBFieldDescriptor *)fieldWithName:(NSString *)name; 85 @end 86 87 @interface GPBFieldDescriptor : NSObject 88 89 @property(nonatomic, readonly, copy) NSString *name; 90 @property(nonatomic, readonly) uint32_t number; 91 @property(nonatomic, readonly) GPBDataType dataType; 92 @property(nonatomic, readonly) BOOL hasDefaultValue; 93 @property(nonatomic, readonly) GPBGenericValue defaultValue; 94 @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. 98 @property(nonatomic, readonly) GPBDataType mapKeyDataType; 99 @property(nonatomic, readonly, getter=isPackable) BOOL packable; 100 101 @property(nonatomic, readonly, assign, nullable) GPBOneofDescriptor *containingOneof; 102 103 // Message properties 104 @property(nonatomic, readonly, assign, nullable) Class msgClass; 105 106 // Enum properties 107 @property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor; 108 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. 113 - (nullable NSString *)textFormatName; 114 115 @end 116 117 @interface GPBEnumDescriptor : NSObject 118 119 @property(nonatomic, readonly, copy) NSString *name; 120 @property(nonatomic, readonly) GPBEnumValidationFunc enumVerifier; 121 122 - (nullable NSString *)enumNameForValue:(int32_t)number; 123 - (BOOL)getValue:(nullable int32_t *)outValue forEnumName:(NSString *)name; 124 125 - (nullable NSString *)textFormatNameForValue:(int32_t)number; 126 - (BOOL)getValue:(nullable int32_t *)outValue forEnumTextFormatName:(NSString *)textFormatName; 127 128 @end 129 130 @interface GPBExtensionDescriptor : NSObject<NSCopying> 131 @property(nonatomic, readonly) uint32_t fieldNumber; 132 @property(nonatomic, readonly) Class containingMessageClass; 133 @property(nonatomic, readonly) GPBDataType dataType; 134 @property(nonatomic, readonly, getter=isRepeated) BOOL repeated; 135 @property(nonatomic, readonly, getter=isPackable) BOOL packable; 136 @property(nonatomic, readonly, assign) Class msgClass; 137 @property(nonatomic, readonly) NSString *singletonName; 138 @property(nonatomic, readonly, strong, nullable) GPBEnumDescriptor *enumDescriptor; 139 @property(nonatomic, readonly, nullable) id defaultValue; 140 @end 141 142 NS_ASSUME_NONNULL_END 143