Google Protocol Buffers, backward reposition IO he

2019-09-05 14:57发布

问题:

I want to move the IO head to the start of a certain CodedOutputStream or ZeroCopyOutputStream so I can update a header data structure with how many protobuf messages are in the file, and how many bytes the following messages consume.

The Backup function is not intended for this, any suggestions ? I am creating a file format for event data, where each file contains multiple event data-sets. I need 2 types of header entities for this (fixed size)A global one, and a per data-set one. I update these after writing in the data-set events. So, How do I move the write header without corrupting the internal state of the stream objects ?.

edit

I wonder, if I flush the stream wrappers and just use the c functions to reseat the head, will this work for the stream classes, or will I end up in undefined land ?

回答1:

I guess the most obvious way would be to have two files instead of each one: The main file with the streamed data, and then an index file with the header information.