Commit 8d6f8df1 authored by Josh Kelley's avatar Josh Kelley Committed by Jie Luo

ParseFromString returns bytes parsed (#5166)

* ParseFromString returns bytes parsed

ParseFromString is documented as returning the number of bytes parsed,
and the C++ implementation does this, so the Python implementation
should too.

See #5165.

* Fix docstring

* Add a test for ParseFromString length behavior
parent 3f826a6d
......@@ -139,9 +139,10 @@ class MessageTest(BaseTestCase):
def testGoldenPackedMessage(self, message_module):
golden_data = test_util.GoldenFileData('golden_packed_fields_message')
golden_message = message_module.TestPackedTypes()
golden_message.ParseFromString(golden_data)
parsed_bytes = golden_message.ParseFromString(golden_data)
all_set = message_module.TestPackedTypes()
test_util.SetAllPackedFields(all_set)
self.assertEqual(parsed_bytes, len(golden_data))
self.assertEqual(all_set, golden_message)
self.assertEqual(golden_data, all_set.SerializeToString())
golden_copy = copy.deepcopy(golden_message)
......
......@@ -178,11 +178,10 @@ class Message(object):
def ParseFromString(self, serialized):
"""Parse serialized protocol buffer data into this message.
Like MergeFromString(), except we clear the object first and
do not return the value that MergeFromString returns.
Like MergeFromString(), except we clear the object first.
"""
self.Clear()
self.MergeFromString(serialized)
return self.MergeFromString(serialized)
def SerializeToString(self, **kwargs):
"""Serializes the protocol message to a binary string.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment