Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protobuf file reading only some field

I have more then 50 fields that is continiously writing in the .proto file but my query is that

1) if I need to read only 10 fields then how can this be achieve.

2) If I need to read partial data from the particular field then how can I achieve.

this should be done without loading all the data from the .proto file.

Thanks for your concern.

like image 921
kamal_tech_view Avatar asked Aug 07 '14 16:08

kamal_tech_view


People also ask

Are Protobuf fields optional?

As of Google Protobuf version 3.15, optional fields are reintroduced in proto3. Embedded Proto supports optional fields as of version 2.3. 0. This feature allows you to track if a field has been set.

How do you deprecate a field in Protobuf?

Protobuf has an option for marking a “field” as deprecated. optional int32 old_field = 6 [deprecated=true]; Full snipped from their documentation: deprecated (field option): If set to true , indicates that the field is deprecated and should not be used by new code.

Can you remove field from Protobuf?

Removing fields is fine, although you might want to mark it reserved so that nobody reuses it in an incompatible way. New code with old data (with the field) will silently ignore it; old code with new data will just load without the field populated, since everything in proto3 is implicitly optional .

Can Protobuf fields be null?

Protobuf treats strings as primitive types and therefore they can not be null. Instead of checking if the string is not null use standard libraries, like apache commons, to check if the string is not blank. This is clear that the value will be inserted if the value is not blank.


1 Answers

This is not really possible with Protobufs. In theory you could write a streaming parser that might be able to extract part of the message without parsing the whole thing, but it would only work if the fields you needed happened to be located towards the front of the message, since you'd at least have to parse through everything before the fields you want. In any case, none of the standard protobuf implementations provide an easy way to do streaming parses, because this isn't the way protobuf is designed to be used. Some third-party implementations, such as upb, might help.

On the other hand, Cap'n Proto, an alternative to Protocol Buffers, does support reading just one field out of a large file, without having to parse the fields before it. It does this by placing fields at fixed offsets and taking advantage of mmap() for large files.

Disclosure: I am the author of both Cap'n Proto and Protocol Buffers v2 (the version open sourced by Google).

like image 177
Kenton Varda Avatar answered Sep 23 '22 17:09

Kenton Varda