aboutsummaryrefslogtreecommitdiffhomepage
path: root/python/google/protobuf/internal/encoder.py
diff options
context:
space:
mode:
authorGravatar Adam Cozzette <acozzette@google.com>2017-04-27 14:55:53 -0700
committerGravatar Adam Cozzette <acozzette@google.com>2017-04-27 14:55:53 -0700
commit9053033a5076f82cf18b823c31f352e95e5bfd8d (patch)
tree1d2a2611f56e786d7c3e40b8fd1b2e3d9aff9025 /python/google/protobuf/internal/encoder.py
parent067b1eec3bf852abaad0844999461baff8a5fdc8 (diff)
parenta6189acd18b00611c1dc7042299ad75486f08a1a (diff)
Merge remote-tracking branch 'remotes/google/3.3.x' into merge-3.3-to-master
Diffstat (limited to 'python/google/protobuf/internal/encoder.py')
-rwxr-xr-xpython/google/protobuf/internal/encoder.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/python/google/protobuf/internal/encoder.py b/python/google/protobuf/internal/encoder.py
index 48ef2df3..80e59cab 100755
--- a/python/google/protobuf/internal/encoder.py
+++ b/python/google/protobuf/internal/encoder.py
@@ -340,7 +340,7 @@ def MessageSetItemSizer(field_number):
# Map is special: it needs custom logic to compute its size properly.
-def MapSizer(field_descriptor):
+def MapSizer(field_descriptor, is_message_map):
"""Returns a sizer for a map field."""
# Can't look at field_descriptor.message_type._concrete_class because it may
@@ -355,9 +355,12 @@ def MapSizer(field_descriptor):
# It's wasteful to create the messages and throw them away one second
# later since we'll do the same for the actual encode. But there's not an
# obvious way to avoid this within the current design without tons of code
- # duplication.
+ # duplication. For message map, value.ByteSize() should be called to
+ # update the status.
entry_msg = message_type._concrete_class(key=key, value=value)
total += message_sizer(entry_msg)
+ if is_message_map:
+ value.ByteSize()
return total
return FieldSize