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.
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.
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.
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 .
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.
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With