Parsing data encoded using proto2 in python

27 views
Skip to first unread message

Roozbeh

unread,
Apr 2, 2020, 9:36:09 AM4/2/20
to Protocol Buffers

I am new to protocol buffers, I am given a signal data saved in .protobin file and I am trying to parse the sensor data in python. I have installed the protoc compiler and compiled the example.proto file with python_out option and extracted example_pb2.py.

I read the file using the following script:

import example_pb2

with open('test_data.protobin','rb') as f:
    data = f.read()

msg = example_pb2.Sensor()
msg.ParseFromString(data)

The test_data.protobin data is 250Mb but the msg is empty and does not contain any information in it.

What am I doing wrong here?


Mac Pham

unread,
Apr 10, 2020, 1:37:52 PM4/10/20
to Protocol Buffers
Are you sure you have one sensor message that is 250Mb? It seems too big to me. Do you know how the protobuf message was written to the file?. It hard to believe it is just one message that big.
If it is more than one sensor message, I think you have to read from the file up to the size of message and parse it.

-Tom
Reply all
Reply to author
Forward
0 new messages