Searching through the protocol buffer file -


i'm new protocol buffers , wondering whether possible search protocol buffers binary file , read data in structured format. example if message in .proto file has 4 fields serialize message , write multiple messages file , search particular field in file. if find field read message in same structured format written. possible protocol buffers ? if possible sample code or examples helpful. thank you

you should treat protobuf library 1 serialization protocol, not all-in-one library supports complex operations (such querying, indexing, picking particular data). google has various libraries on top of open-sourced portion of protobuf so, not released open source, tied unique infrastructure. being said, want possible, yet need write code.

anyhow, of requirements are:

  1. one file contains various serialized binaries.
  2. search particular field in each serialized binary , extract chunk.

there several ways achieve them.

  1. the popular way serial read/write file contains series of [size, type, serialization output]. is, 1 serialized output prefixed size , type (either 4/8 byte or variable-length) reading , parsing. repeat procedure: 1) read size , type, 2) read binary given size, 3) parse given type 4) goto 1). if use union type or 1 file shares same type, may skip type. cannot drop size, there no way know end of output itself. if want random read/write, other type of data structure necessary.

  2. 'search field' in binary file more tricky. 1 way read/parse output 1 one , check existance of field hasfield(). obvious , slow yet straightforward way so. if want search field number (say, want search 'optional string email = 3;'), search binary blob (like 0x1a, field number 3, wire type 2), not possible. in serialized binary stream, field information saved merely number. without exact context (.proto scheme or binary file's structure), number alone doesn't mean anything. there no guarantee 0x1a field information, or field information other message type, or number 26, or part of other number, etc. is, need maintain information yourself. may create file or database necessary information fetch particular message (like location of serialization output given field).

long story short, ask beyond open-sourced protobuf library does, yet can write them requirements.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -