3

I have buffer that encoded with protocol-buffer , I want to read the buffer and change some data and encode it again.

I saw that when I encode the buffer ( SerializeToString) the binary data is not the same so the server that get that buffer can't decoded that .

import messages_pb2
with open('proto.bin','rb') as f:
    buffer1 = f.read()
my_obj1 = messages_pb2.MyObj()
my_obj1.ParseFromString(buffer1)
buffer2 = my_obj1.SerializeToString()

When I look at the binary data I think that the order of the data is changed. Is there any way to SerializeToString but the choose the order of data ?

python3.789
  • 164
  • 9

1 Answers1

2

As mentionned in the Protocol Buffer documentation:

When a message is serialized, there is no guaranteed order for how its known or unknown fields will be written.

However, this shouldn't be a problem if you are using Protocol Buffers to deserialize the data. If you have a custom parsing algorithm that parses that data, then you might want to either refine the algorithm to not care about the order, or use Protocol Buffers.

As I don't have much more information here, please let me know how I can better help.

Clément Jean
  • 1,735
  • 1
  • 14
  • 32