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
f35669b8
Unverified
Commit
f35669b8
authored
6 years ago
by
Feng Xiao
Committed by
GitHub
6 years ago
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4812 from htuch/fix-any-case
protostream_objectsource: preserve print options across Any.
parents
1f77342b
395ae4f7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
88 additions
and
0 deletions
+88
-0
protostream_objectsource.cc
...google/protobuf/util/internal/protostream_objectsource.cc
+7
-0
protostream_objectsource_test.cc
...e/protobuf/util/internal/protostream_objectsource_test.cc
+78
-0
books.proto
src/google/protobuf/util/internal/testdata/books.proto
+3
-0
No files found.
src/google/protobuf/util/internal/protostream_objectsource.cc
View file @
f35669b8
...
...
@@ -648,6 +648,13 @@ Status ProtoStreamObjectSource::RenderAny(const ProtoStreamObjectSource* os,
// using a nested ProtoStreamObjectSource using our nested type information.
ProtoStreamObjectSource
nested_os
(
&
in_stream
,
os
->
typeinfo_
,
*
nested_type
);
// TODO(htuch): This is somewhat fragile, since new options may be omitted.
// We should probably do this via the constructor or some object grouping
// options.
nested_os
.
set_use_lower_camel_for_enums
(
os
->
use_lower_camel_for_enums_
);
nested_os
.
set_use_ints_for_enums
(
os
->
use_ints_for_enums_
);
nested_os
.
set_preserve_proto_field_names
(
os
->
preserve_proto_field_names_
);
// We manually call start and end object here so we can inject the @type.
ow
->
StartObject
(
field_name
);
ow
->
RenderString
(
"@type"
,
type_url
);
...
...
This diff is collapsed.
Click to expand it.
src/google/protobuf/util/internal/protostream_objectsource_test.cc
View file @
f35669b8
...
...
@@ -100,6 +100,7 @@ class ProtostreamObjectSourceTest
ow_
(
&
mock_
),
use_lower_camel_for_enums_
(
false
),
use_ints_for_enums_
(
false
),
use_preserve_proto_field_names_
(
false
),
add_trailing_zeros_
(
false
),
render_unknown_enum_values_
(
true
)
{
helper_
.
ResetTypeInfo
(
Book
::
descriptor
(),
Proto3Message
::
descriptor
());
...
...
@@ -123,6 +124,7 @@ class ProtostreamObjectSourceTest
helper_
.
NewProtoSource
(
&
in_stream
,
GetTypeUrl
(
descriptor
)));
if
(
use_lower_camel_for_enums_
)
os
->
set_use_lower_camel_for_enums
(
true
);
if
(
use_ints_for_enums_
)
os
->
set_use_ints_for_enums
(
true
);
if
(
use_preserve_proto_field_names_
)
os
->
set_preserve_proto_field_names
(
true
);
os
->
set_max_recursion_depth
(
64
);
return
os
->
WriteTo
(
&
mock_
);
}
...
...
@@ -272,6 +274,8 @@ class ProtostreamObjectSourceTest
void
UseIntsForEnums
()
{
use_ints_for_enums_
=
true
;
}
void
UsePreserveProtoFieldNames
()
{
use_preserve_proto_field_names_
=
true
;
}
void
AddTrailingZeros
()
{
add_trailing_zeros_
=
true
;
}
void
SetRenderUnknownEnumValues
(
bool
value
)
{
...
...
@@ -284,6 +288,7 @@ class ProtostreamObjectSourceTest
ExpectingObjectWriter
ow_
;
bool
use_lower_camel_for_enums_
;
bool
use_ints_for_enums_
;
bool
use_preserve_proto_field_names_
;
bool
add_trailing_zeros_
;
bool
render_unknown_enum_values_
;
};
...
...
@@ -536,6 +541,16 @@ TEST_P(ProtostreamObjectSourceTest, UseIntsForEnumsTest) {
DoTest
(
book
,
Book
::
descriptor
());
}
TEST_P
(
ProtostreamObjectSourceTest
,
UsePreserveProtoFieldNames
)
{
Book
book
;
book
.
set_snake_field
(
"foo"
);
UsePreserveProtoFieldNames
();
ow_
.
StartObject
(
""
)
->
RenderString
(
"snake_field"
,
"foo"
)
->
EndObject
();
DoTest
(
book
,
Book
::
descriptor
());
}
TEST_P
(
ProtostreamObjectSourceTest
,
UnknownEnumAreDroppedWhenRenderUnknownEnumValuesIsUnset
)
{
Proto3Message
message
;
...
...
@@ -769,6 +784,69 @@ TEST_P(ProtostreamObjectSourceAnysTest, BasicAny) {
DoTest
(
out
,
AnyOut
::
descriptor
());
}
TEST_P
(
ProtostreamObjectSourceAnysTest
,
LowerCamelEnumOutputSnakeCase
)
{
AnyOut
out
;
::
google
::
protobuf
::
Any
*
any
=
out
.
mutable_any
();
Book
book
;
book
.
set_type
(
Book
::
arts_and_photography
);
any
->
PackFrom
(
book
);
UseLowerCamelForEnums
();
ow_
.
StartObject
(
""
)
->
StartObject
(
"any"
)
->
RenderString
(
"@type"
,
"type.googleapis.com/google.protobuf.testing.Book"
)
->
RenderString
(
"type"
,
"artsAndPhotography"
)
->
EndObject
()
->
EndObject
();
DoTest
(
out
,
AnyOut
::
descriptor
());
}
TEST_P
(
ProtostreamObjectSourceAnysTest
,
UseIntsForEnumsTest
)
{
AnyOut
out
;
::
google
::
protobuf
::
Any
*
any
=
out
.
mutable_any
();
Book
book
;
book
.
set_type
(
Book
::
ACTION_AND_ADVENTURE
);
any
->
PackFrom
(
book
);
UseIntsForEnums
();
ow_
.
StartObject
(
""
)
->
StartObject
(
"any"
)
->
RenderString
(
"@type"
,
"type.googleapis.com/google.protobuf.testing.Book"
)
->
RenderInt32
(
"type"
,
3
)
->
EndObject
()
->
EndObject
();
DoTest
(
out
,
AnyOut
::
descriptor
());
}
TEST_P
(
ProtostreamObjectSourceAnysTest
,
UsePreserveProtoFieldNames
)
{
AnyOut
out
;
::
google
::
protobuf
::
Any
*
any
=
out
.
mutable_any
();
Book
book
;
book
.
set_snake_field
(
"foo"
);
any
->
PackFrom
(
book
);
UsePreserveProtoFieldNames
();
ow_
.
StartObject
(
""
)
->
StartObject
(
"any"
)
->
RenderString
(
"@type"
,
"type.googleapis.com/google.protobuf.testing.Book"
)
->
RenderString
(
"snake_field"
,
"foo"
)
->
EndObject
()
->
EndObject
();
DoTest
(
out
,
AnyOut
::
descriptor
());
}
TEST_P
(
ProtostreamObjectSourceAnysTest
,
RecursiveAny
)
{
AnyOut
out
;
::
google
::
protobuf
::
Any
*
any
=
out
.
mutable_any
();
...
...
This diff is collapsed.
Click to expand it.
src/google/protobuf/util/internal/testdata/books.proto
View file @
f35669b8
...
...
@@ -69,6 +69,9 @@ message Book {
}
optional
Type
type
=
11
;
// Useful for testing JSON snake/camel-case conversions.
optional
string
snake_field
=
12
;
extensions
200
to
499
;
}
...
...
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