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
cad0258d
Commit
cad0258d
authored
Apr 11, 2017
by
Feng Xiao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cherry-pick cl/151775298
parent
fc3ea978
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
2 deletions
+56
-2
map_test.cc
src/google/protobuf/map_test.cc
+27
-0
wire_format.cc
src/google/protobuf/wire_format.cc
+29
-2
No files found.
src/google/protobuf/map_test.cc
View file @
cad0258d
...
...
@@ -2811,6 +2811,33 @@ TEST(WireFormatForMapFieldTest, SerializeMap) {
EXPECT_TRUE
(
dynamic_data
==
generated_data
);
}
TEST
(
WireFormatForMapFieldTest
,
SerializeMapDynamicMessage
)
{
DynamicMessageFactory
factory
;
google
::
protobuf
::
scoped_ptr
<
Message
>
dynamic_message
;
dynamic_message
.
reset
(
factory
.
GetPrototype
(
unittest
::
TestMap
::
descriptor
())
->
New
());
MapReflectionTester
reflection_tester
(
unittest
::
TestMap
::
descriptor
());
reflection_tester
.
SetMapFieldsViaReflection
(
dynamic_message
.
get
());
reflection_tester
.
ExpectMapFieldsSetViaReflection
(
*
dynamic_message
);
unittest
::
TestMap
generated_message
;
MapTestUtil
::
SetMapFields
(
&
generated_message
);
MapTestUtil
::
ExpectMapFieldsSet
(
generated_message
);
string
generated_data
;
string
dynamic_data
;
// Serialize.
generated_message
.
SerializeToString
(
&
generated_data
);
dynamic_message
->
SerializeToString
(
&
dynamic_data
);
// Because map serialization doesn't guarantee order, we just compare
// serialized size here. This is enough to tell dynamic message doesn't miss
// anything in serialization.
EXPECT_TRUE
(
dynamic_data
.
size
()
==
generated_data
.
size
());
}
TEST
(
WireFormatForMapFieldTest
,
MapParseHelpers
)
{
string
data
;
...
...
src/google/protobuf/wire_format.cc
View file @
cad0258d
...
...
@@ -797,7 +797,16 @@ void WireFormat::SerializeWithCachedSizes(
int
expected_endpoint
=
output
->
ByteCount
()
+
size
;
std
::
vector
<
const
FieldDescriptor
*>
fields
;
message_reflection
->
ListFields
(
message
,
&
fields
);
// Fields of map entry should always be serialized.
if
(
descriptor
->
options
().
map_entry
())
{
for
(
int
i
=
0
;
i
<
descriptor
->
field_count
();
i
++
)
{
fields
.
push_back
(
descriptor
->
field
(
i
));
}
}
else
{
message_reflection
->
ListFields
(
message
,
&
fields
);
}
for
(
int
i
=
0
;
i
<
fields
.
size
();
i
++
)
{
SerializeFieldWithCachedSizes
(
fields
[
i
],
message
,
output
);
}
...
...
@@ -834,6 +843,9 @@ void WireFormat::SerializeFieldWithCachedSizes(
if
(
field
->
is_repeated
())
{
count
=
message_reflection
->
FieldSize
(
message
,
field
);
}
else
if
(
field
->
containing_type
()
->
options
().
map_entry
())
{
// Map entry fields always need to be serialized.
count
=
1
;
}
else
if
(
message_reflection
->
HasField
(
message
,
field
))
{
count
=
1
;
}
...
...
@@ -984,7 +996,16 @@ size_t WireFormat::ByteSize(const Message& message) {
size_t
our_size
=
0
;
std
::
vector
<
const
FieldDescriptor
*>
fields
;
message_reflection
->
ListFields
(
message
,
&
fields
);
// Fields of map entry should always be serialized.
if
(
descriptor
->
options
().
map_entry
())
{
for
(
int
i
=
0
;
i
<
descriptor
->
field_count
();
i
++
)
{
fields
.
push_back
(
descriptor
->
field
(
i
));
}
}
else
{
message_reflection
->
ListFields
(
message
,
&
fields
);
}
for
(
int
i
=
0
;
i
<
fields
.
size
();
i
++
)
{
our_size
+=
FieldByteSize
(
fields
[
i
],
message
);
}
...
...
@@ -1015,6 +1036,9 @@ size_t WireFormat::FieldByteSize(
size_t
count
=
0
;
if
(
field
->
is_repeated
())
{
count
=
FromIntSize
(
message_reflection
->
FieldSize
(
message
,
field
));
}
else
if
(
field
->
containing_type
()
->
options
().
map_entry
())
{
// Map entry fields always need to be serialized.
count
=
1
;
}
else
if
(
message_reflection
->
HasField
(
message
,
field
))
{
count
=
1
;
}
...
...
@@ -1044,6 +1068,9 @@ size_t WireFormat::FieldDataOnlyByteSize(
if
(
field
->
is_repeated
())
{
count
=
internal
::
FromIntSize
(
message_reflection
->
FieldSize
(
message
,
field
));
}
else
if
(
field
->
containing_type
()
->
options
().
map_entry
())
{
// Map entry fields always need to be serialized.
count
=
1
;
}
else
if
(
message_reflection
->
HasField
(
message
,
field
))
{
count
=
1
;
}
...
...
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