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
2bcd43af
Commit
2bcd43af
authored
8 years ago
by
Thomas Van Lenten
Committed by
GitHub
8 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1714 from dnkoutso/master
Get value from text format name in GPBEnumDescriptor
parents
0ab78e19
37ca94f8
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 @
2bcd43af
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
objectivec/GPBDescriptor.m
View file @
2bcd43af
...
...
@@ -756,6 +756,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
];
...
...
This diff is collapsed.
Click to expand it.
objectivec/Tests/GPBDescriptorTests.m
View file @
2bcd43af
...
...
@@ -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
{
...
...
This diff is collapsed.
Click to expand it.
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