GPBDescriptor.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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. #import <Foundation/Foundation.h>
  31. #import "GPBRuntimeTypes.h"
  32. @class GPBEnumDescriptor;
  33. @class GPBFieldDescriptor;
  34. @class GPBFieldOptions;
  35. @class GPBFileDescriptor;
  36. @class GPBOneofDescriptor;
  37. typedef NS_ENUM(NSInteger, GPBFileSyntax) {
  38. GPBFileSyntaxUnknown = 0,
  39. GPBFileSyntaxProto2 = 2,
  40. GPBFileSyntaxProto3 = 3,
  41. };
  42. typedef NS_ENUM(NSInteger, GPBFieldType) {
  43. GPBFieldTypeSingle, // optional/required
  44. GPBFieldTypeRepeated, // repeated
  45. GPBFieldTypeMap, // map<K,V>
  46. };
  47. @interface GPBDescriptor : NSObject<NSCopying>
  48. @property(nonatomic, readonly, copy) NSString *name;
  49. @property(nonatomic, readonly, strong) NSArray *fields;
  50. @property(nonatomic, readonly, strong) NSArray *oneofs;
  51. @property(nonatomic, readonly, strong) NSArray *enums;
  52. @property(nonatomic, readonly) const GPBExtensionRange *extensionRanges;
  53. @property(nonatomic, readonly) NSUInteger extensionRangesCount;
  54. @property(nonatomic, readonly, assign) GPBFileDescriptor *file;
  55. @property(nonatomic, readonly, getter=isWireFormat) BOOL wireFormat;
  56. @property(nonatomic, readonly) Class messageClass;
  57. - (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
  58. - (GPBFieldDescriptor *)fieldWithName:(NSString *)name;
  59. - (GPBOneofDescriptor *)oneofWithName:(NSString *)name;
  60. - (GPBEnumDescriptor *)enumWithName:(NSString *)name;
  61. @end
  62. @interface GPBFileDescriptor : NSObject
  63. @property(nonatomic, readonly, copy) NSString *package;
  64. @property(nonatomic, readonly) GPBFileSyntax syntax;
  65. @end
  66. @interface GPBOneofDescriptor : NSObject
  67. @property(nonatomic, readonly) NSString *name;
  68. @property(nonatomic, readonly) NSArray *fields;
  69. - (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
  70. - (GPBFieldDescriptor *)fieldWithName:(NSString *)name;
  71. @end
  72. @interface GPBFieldDescriptor : NSObject
  73. @property(nonatomic, readonly, copy) NSString *name;
  74. @property(nonatomic, readonly) uint32_t number;
  75. @property(nonatomic, readonly) GPBDataType dataType;
  76. @property(nonatomic, readonly) BOOL hasDefaultValue;
  77. @property(nonatomic, readonly) GPBGenericValue defaultValue;
  78. @property(nonatomic, readonly, getter=isRequired) BOOL required;
  79. @property(nonatomic, readonly, getter=isOptional) BOOL optional;
  80. @property(nonatomic, readonly) GPBFieldType fieldType;
  81. // If it is a map, the value type is in -type.
  82. @property(nonatomic, readonly) GPBDataType mapKeyDataType;
  83. @property(nonatomic, readonly, getter=isPackable) BOOL packable;
  84. @property(nonatomic, readonly, assign) GPBOneofDescriptor *containingOneof;
  85. @property(nonatomic, readonly) GPBFieldOptions *fieldOptions;
  86. // Message properties
  87. @property(nonatomic, readonly, assign) Class msgClass;
  88. // Enum properties
  89. @property(nonatomic, readonly, strong) GPBEnumDescriptor *enumDescriptor;
  90. - (BOOL)isValidEnumValue:(int32_t)value;
  91. // For now, this will return nil if it doesn't know the name to use for
  92. // TextFormat.
  93. - (NSString *)textFormatName;
  94. @end
  95. @interface GPBEnumDescriptor : NSObject
  96. @property(nonatomic, readonly, copy) NSString *name;
  97. @property(nonatomic, readonly) GPBEnumValidationFunc enumVerifier;
  98. - (NSString *)enumNameForValue:(int32_t)number;
  99. - (BOOL)getValue:(int32_t *)outValue forEnumName:(NSString *)name;
  100. - (NSString *)textFormatNameForValue:(int32_t)number;
  101. @end
  102. @interface GPBExtensionDescriptor : NSObject<NSCopying>
  103. @property(nonatomic, readonly) uint32_t fieldNumber;
  104. @property(nonatomic, readonly) Class containingMessageClass;
  105. @property(nonatomic, readonly) GPBDataType dataType;
  106. @property(nonatomic, readonly, getter=isRepeated) BOOL repeated;
  107. @property(nonatomic, readonly, getter=isPackable) BOOL packable;
  108. @property(nonatomic, readonly, assign) Class msgClass;
  109. @property(nonatomic, readonly) NSString *singletonName;
  110. @property(nonatomic, readonly, strong) GPBEnumDescriptor *enumDescriptor;
  111. @property(nonatomic, readonly) id defaultValue;
  112. @end