how to parse only one field from protobuf Serialize byte array

1.2k views Asked by At

I need only one field from protobuf serialize byte array, but must call parseFrom function, which is low performance. how can I get field offset from byte array, and parse value by offset.

1

There are 1 answers

0
Clément Jean On

As mentioned in the Protocol Buffers documentation on fields order:

When a message is serialized, there is no guaranteed order for how its known or unknown fields will be written. Serialization order is an implementation detail, and the details of any particular implementation may change in the future. Therefore, protocol buffer parsers must be able to parse fields in any order.

Therefore you cannot have a 100% reliable offset to a field. You will need to call the ParseFrom function.