GPBDescriptor.h 5.4 KB

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