Skip to content Skip to sidebar Skip to footer

Using Python, How Do I Get A Binary Serialization Of My Google Protobuf Message?

I see the function SerializeAsString in the protobuf Python documentation, but like this suggests, this gives me a string version of the binary data. Is there a way of serializing

Solution 1:

Python strings can hold binary data, therefore SerializeAsString returns binary data.

Solution 2:

I think that strings are the usual way to represent binary data in Python. What do you exactly want to do?

[Edit]

Have a look at the struct module: http://docs.python.org/library/struct.html

Solution 3:

It not clear what you want to do:

  1. Do something with the serialized form of an entire message (From the SerializeAsString method). Not sure what you'd want to do with this?
  2. Store a byte string inside a protobuf message - just use the bytes type in the .proto file, and a byte string in python for the variable.

Solution 4:

You can use Pythons Strings for getting proto buffers serialized data (doesn't matter how they ware crated - in Python, Java, C++ or any other language).

These is line from Pythons version of proto buffers tutorial: address_book.ParseFromString(f.read())

Post a Comment for "Using Python, How Do I Get A Binary Serialization Of My Google Protobuf Message?"