Python API to parse binary file which contains protobuf data in array format

64 views
Skip to first unread message

Silpa Ks

unread,
May 7, 2018, 5:26:07 AM5/7/18
to Protocol Buffers

Hi,

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?

Roozbeh

unread,
Apr 2, 2020, 10:09:40 AM4/2/20
to Protocol Buffers
Hi,

I am having a similar issue! Did you figure out how to resolve this?

Mac Pham

unread,
Apr 9, 2020, 1:28:06 PM4/9/20
to Protocol Buffers

Mac Pham

unread,
Apr 9, 2020, 1:35:34 PM4/9/20
to Protocol Buffers

  From C++ I used SerializeToString 
 Ex:
 string output;
 response->SerializeToString(&output);

 In python:
 if I use UDP to receive it , I use PBWrapper.FromString(message[0]) where message contains data I received from UDP socket
 For TCP just use PBWrapper.FromString(message)

And it worked for me.

-Tom

On Monday, May 7, 2018 at 2:26:07 AM UTC-7, Silpa Ks wrote:

Roozbeh

unread,
Apr 10, 2020, 9:21:34 AM4/10/20
to Protocol Buffers
Thank you for your reply. I am trying to load saved data. I use the following script but it is empty after I run it:
import example_pb2

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

msg
= example_pb2.Sensor()
msg
.ParseFromString(data) # or
msg.FromString(data)

Do you know what I'm doing wrong? 
Reply all
Reply to author
Forward
0 new messages