aboutsummaryrefslogtreecommitdiffhomepage
path: root/objectivec/GPBDescriptor.h
diff options
context:
space:
mode:
authorGravatar leovitch <leovitch+github@gmail.com>2018-05-29 21:08:00 +0900
committerGravatar Thomas Van Lenten <thomasvl@google.com>2018-05-29 08:08:00 -0400
commit2804902446bf6f3d7d2a58fad7a053034dfcda84 (patch)
treed73a2621460311decf7323f794f7c7c557d64d98 /objectivec/GPBDescriptor.h
parent264e615e8e771b09a10a4da012a3edabea69651d (diff)
[ObjC] Add ability to introspect list of enum values (#4678)
Added new API to GPBEnumDescriptor to enable introspection of enum values. Refactored implementation so that this contains a minimum of added code. Clarified comments regarding behavior in the presence of the alias_allowed option. Added unit tests for new functionality and for the alias case.
Diffstat (limited to 'objectivec/GPBDescriptor.h')
-rw-r--r--objectivec/GPBDescriptor.h34
1 files changed, 32 insertions, 2 deletions
diff --git a/objectivec/GPBDescriptor.h b/objectivec/GPBDescriptor.h
index 651f4de0..292bce13 100644
--- a/objectivec/GPBDescriptor.h
+++ b/objectivec/GPBDescriptor.h
@@ -223,9 +223,12 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
/**
* Returns the enum value name for the given raw enum.
*
+ * Note that there can be more than one name corresponding to a given value
+ * if the allow_alias option is used.
+ *
* @param number The raw enum value.
*
- * @return The name of the enum value passed, or nil if not valid.
+ * @return The first name that matches the enum value passed, or nil if not valid.
**/
- (nullable NSString *)enumNameForValue:(int32_t)number;
@@ -244,7 +247,7 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
*
* @param number The raw enum value.
*
- * @return The text format name for the raw enum value, or nil if not valid.
+ * @return The first text format name which matches the enum value, or nil if not valid.
**/
- (nullable NSString *)textFormatNameForValue:(int32_t)number;
@@ -258,6 +261,33 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
**/
- (BOOL)getValue:(nullable int32_t *)outValue forEnumTextFormatName:(NSString *)textFormatName;
+/**
+ * Gets the number of defined enum names.
+ *
+ * @return Count of the number of enum names, including any aliases.
+ */
+@property(nonatomic, readonly) uint32_t enumNameCount;
+
+/**
+ * Gets the enum name corresponding to the given index.
+ *
+ * @param index Index into the available names. The defined range is from 0
+ * to self.enumNameCount - 1.
+ *
+ * @returns The enum name at the given index, or nil if the index is out of range.
+ */
+- (nullable NSString *)getEnumNameForIndex:(uint32_t)index;
+
+/**
+ * Gets the enum text format name corresponding to the given index.
+ *
+ * @param index Index into the available names. The defined range is from 0
+ * to self.enumNameCount - 1.
+ *
+ * @returns The text format name at the given index, or nil if the index is out of range.
+ */
+- (nullable NSString *)getEnumTextFormatNameForIndex:(uint32_t)index;
+
@end
/**