GPBDescriptor.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 "GPBTypes.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, strong) NSArray *extensions;
  53. @property(nonatomic, readonly) const GPBExtensionRange *extensionRanges;
  54. @property(nonatomic, readonly) NSUInteger extensionRangesCount;
  55. @property(nonatomic, readonly, assign) GPBFileDescriptor *file;
  56. @property(nonatomic, readonly, getter=isWireFormat) BOOL wireFormat;
  57. @property(nonatomic, readonly) Class messageClass;
  58. - (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
  59. - (GPBFieldDescriptor *)fieldWithName:(NSString *)name;
  60. - (GPBOneofDescriptor *)oneofWithName:(NSString *)name;
  61. - (GPBEnumDescriptor *)enumWithName:(NSString *)name;
  62. - (GPBFieldDescriptor *)extensionWithNumber:(uint32_t)fieldNumber;
  63. - (GPBFieldDescriptor *)extensionWithName:(NSString *)name;
  64. @end
  65. @interface GPBFileDescriptor : NSObject
  66. @property(nonatomic, readonly, copy) NSString *package;
  67. @property(nonatomic, readonly) GPBFileSyntax syntax;
  68. @end
  69. @interface GPBOneofDescriptor : NSObject
  70. @property(nonatomic, readonly) NSString *name;
  71. @property(nonatomic, readonly) NSArray *fields;
  72. - (GPBFieldDescriptor *)fieldWithNumber:(uint32_t)fieldNumber;
  73. - (GPBFieldDescriptor *)fieldWithName:(NSString *)name;
  74. @end
  75. @interface GPBFieldDescriptor : NSObject
  76. @property(nonatomic, readonly, copy) NSString *name;
  77. @property(nonatomic, readonly) uint32_t number;
  78. @property(nonatomic, readonly) GPBType type;
  79. @property(nonatomic, readonly) BOOL hasDefaultValue;
  80. @property(nonatomic, readonly) GPBValue defaultValue;
  81. @property(nonatomic, readonly, getter=isRequired) BOOL required;
  82. @property(nonatomic, readonly, getter=isOptional) BOOL optional;
  83. @property(nonatomic, readonly) GPBFieldType fieldType;
  84. // If it is a map, the value type is in -type.
  85. @property(nonatomic, readonly) GPBType mapKeyType;
  86. @property(nonatomic, readonly, getter=isPackable) BOOL packable;
  87. @property(nonatomic, readonly, assign) GPBOneofDescriptor *containingOneof;
  88. @property(nonatomic, readonly) GPBFieldOptions *fieldOptions;
  89. // Message properties
  90. @property(nonatomic, readonly, assign) Class msgClass;
  91. // Enum properties
  92. @property(nonatomic, readonly, strong) GPBEnumDescriptor *enumDescriptor;
  93. - (BOOL)isValidEnumValue:(int32_t)value;
  94. // For now, this will return nil if it doesn't know the name to use for
  95. // TextFormat.
  96. - (NSString *)textFormatName;
  97. @end
  98. @interface GPBEnumDescriptor : NSObject
  99. @property(nonatomic, readonly, copy) NSString *name;
  100. @property(nonatomic, readonly) GPBEnumValidationFunc enumVerifier;
  101. - (NSString *)enumNameForValue:(int32_t)number;
  102. - (BOOL)getValue:(int32_t *)outValue forEnumName:(NSString *)name;
  103. - (NSString *)textFormatNameForValue:(int32_t)number;
  104. @end
  105. @interface GPBExtensionDescriptor : NSObject
  106. @property(nonatomic, readonly) uint32_t fieldNumber;
  107. @property(nonatomic, readonly) GPBType type;
  108. @property(nonatomic, readonly, getter=isRepeated) BOOL repeated;
  109. @property(nonatomic, readonly, getter=isPackable) BOOL packable;
  110. @property(nonatomic, readonly, assign) Class msgClass;
  111. @property(nonatomic, readonly) NSString *singletonName;
  112. @property(nonatomic, readonly, strong) GPBEnumDescriptor *enumDescriptor;
  113. @end