Google Protocol Buffers,在提供的流对象中向后重新定位 IO 头 [英] Google Protocol Buffers, backward reposition IO head in the stream objects provided
问题描述
我想将 IO 头移动到某个 CodedOutputStream 或 ZeroCopyOutputStream 的开头,以便我可以使用文件中有多少 protobuf 消息以及以下消息消耗多少字节来更新头数据结构.
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 ?.
编辑
我想知道,如果我刷新流包装器并仅使用 c 函数来重新安装头部,这是否适用于流类,还是最终会处于未定义的状态?
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 ?
推荐答案
我想最明显的方法是有两个文件而不是每个文件:带有流数据的主文件,然后是带有标题的索引文件信息.
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.
这篇关于Google Protocol Buffers,在提供的流对象中向后重新定位 IO 头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!