Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
37ca94f8
Commit
37ca94f8
authored
Jun 25, 2016
by
Dimitris Koutsogiorgas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Get value from text format name in GPBEnumDescriptor
parent
325cc42e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
0 deletions
+26
-0
GPBDescriptor.h
objectivec/GPBDescriptor.h
+1
-0
GPBDescriptor.m
objectivec/GPBDescriptor.m
+17
-0
GPBDescriptorTests.m
objectivec/Tests/GPBDescriptorTests.m
+8
-0
No files found.
objectivec/GPBDescriptor.h
View file @
37ca94f8
...
...
@@ -123,6 +123,7 @@ typedef NS_ENUM(uint8_t, GPBFieldType) {
-
(
BOOL
)
getValue
:(
nullable
int32_t
*
)
outValue
forEnumName
:(
NSString
*
)
name
;
-
(
nullable
NSString
*
)
textFormatNameForValue
:(
int32_t
)
number
;
-
(
BOOL
)
getValue
:(
nullable
int32_t
*
)
outValue
forEnumTextFormatName
:(
NSString
*
)
textFormatName
;
@end
...
...
objectivec/GPBDescriptor.m
View file @
37ca94f8
...
...
@@ -745,6 +745,23 @@ uint32_t GPBFieldAlternateTag(GPBFieldDescriptor *self) {
return
NO
;
}
-
(
BOOL
)
getValue
:
(
int32_t
*
)
outValue
forEnumTextFormatName
:
(
NSString
*
)
textFormatName
;
{
if
(
nameOffsets_
==
NULL
)
[
self
calcValueNameOffsets
];
for
(
uint32_t
i
=
0
;
i
<
valueCount_
;
++
i
)
{
int32_t
value
=
values_
[
i
];
NSString
*
valueTextFormatName
=
[
self
textFormatNameForValue
:
value
];
if
([
valueTextFormatName
isEqual
:
textFormatName
])
{
if
(
outValue
)
{
*
outValue
=
value
;
}
return
YES
;
}
}
return
NO
;
}
-
(
NSString
*
)
textFormatNameForValue
:
(
int32_t
)
number
{
if
(
nameOffsets_
==
NULL
)
[
self
calcValueNameOffsets
];
...
...
objectivec/Tests/GPBDescriptorTests.m
View file @
37ca94f8
...
...
@@ -125,6 +125,12 @@
[
descriptor
getValue
:
&
value
forEnumName
:
@"TestAllTypes_NestedEnum_Baz"
]);
XCTAssertEqual
(
value
,
TestAllTypes_NestedEnum_Baz
);
// TextFormat
enumName
=
[
descriptor
textFormatNameForValue
:
1
];
XCTAssertNotNil
(
enumName
);
XCTAssertTrue
([
descriptor
getValue
:
&
value
forEnumTextFormatName
:
@"FOO"
]);
XCTAssertEqual
(
value
,
TestAllTypes_NestedEnum_Foo
);
// Bad values
enumName
=
[
descriptor
enumNameForValue
:
0
];
XCTAssertNil
(
enumName
);
...
...
@@ -134,6 +140,8 @@
forEnumName
:
@"TestAllTypes_NestedEnum_Unknown"
]);
XCTAssertFalse
([
descriptor
getValue
:
NULL
forEnumName
:
@"TestAllTypes_NestedEnum_Unknown"
]);
XCTAssertFalse
([
descriptor
getValue
:
NULL
forEnumTextFormatName
:
@"Unknown"
]);
XCTAssertFalse
([
descriptor
getValue
:
&
value
forEnumTextFormatName
:
@"Unknown"
]);
}
-
(
void
)
testEnumValueValidator
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment