Skip to content Skip to sidebar Skip to footer

Python Protobuf Can't Deserialize Message

Getting started with protobuf in python I face a strange issue: a simple message proto definition is: syntax = 'proto3'; package test; message Message { string message = 1; st

Solution 1:

Instead of

a = m.ParseFromString(s_m)
a.foo

do this

a = m.FromString(s_m)
print a.sender

alternatively you can do this

m2 = Message()
m2.ParseFromString(s_m)
print m2.sender

The difference is that FromString returns a new object deserialized from the string whereas ParseFromString parses the string and sets the fields on the object.

Post a Comment for "Python Protobuf Can't Deserialize Message"