Google Protocol Buffers, backward reposition IO head in the stream objects provided

痴心易碎 提交于 2019-12-13 04:18:27

问题


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.



来源:https://stackoverflow.com/questions/10031911/google-protocol-buffers-backward-reposition-io-head-in-the-stream-objects-provi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!