3

I'm facing problem in parsing binary file containing protobuf data in array format.

When I used the python API, ParseFromString output was always zero or none.

The serialized protobuf data in the binary file was generated using C++ API, SerializeToArray. But to parse the bin file, I want to use python for parsing. But in python I couldn't find any API to parse serialized protobuf data as array in binary file.

Is there any python API to resolve this issue? Can anyone please suggest a solution for this?

1 Answer 1

1

The C++ interface:

bool SerializeToArray(void * data, int size) const

just stores the binary data into a byte array, instead of a string object. If it is then written to file, it can be deserialized in the normal way, as shown in the tutorial:

address_book = addressbook_pb2.AddressBook()
f = open(sys.argv[1], "rb")
address_book.ParseFromString(f.read())

The fact that SerializeToArray() was used on C++ side does not change the format of the file. Of course the C++ code could e.g. write a custom header to the file that needs to be removed, but that would be a different part of the code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.