Using Python, how do I get a binary serialization of my Google protobuf message?

19,060

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

Share:
19,060
Nick Bolton
Author by

Nick Bolton

Hello, I'm the CEO of Symless, the company behind Synergy, software that lets you share one mouse and keyboard between multiple computers.

Updated on June 05, 2022

Comments

  • Nick Bolton
    Nick Bolton almost 2 years

    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 and parsing a binary array of protobuf data using Python?

    We have a C++ application that stores the protobuf messages as binary data in a file. We'd like to read and write to the file using Python.