NULL
完整文章,请查看:http://www.codelast.com/?p=316
Techniques 技巧
注:这是 本人的翻译,可能不准确,可能有错误,但是基本上可以理解,希望能对大家有所帮助!(转载请注明出处:本文来自learnhard的博客:http://www.codelast.com/ & http://blog.csdn.net/learnhard/)
This page describes some commonly-used design patterns for dealing with Protocol Buffers. You can also send design and usage questions to the Protocol Buffers discussion group.
l 将多个消息转化为流
l 大数据集
l 联合类型
l 自描述的消息
本文描述了处理Protocol Buffers的时候一些常用的设计模式。你也可以向Protocol Buffers讨论组(Protocol Buffers discussion group)发送设计和使用方面的问题寻求解答。
Streaming Multiple Messages 将多个消息转化为流
If you want to write multiple messages to a single file or stream, it is up to you to keep track of where one message ends and the next begins. The Protocol Buffer wire format is not self-delimiting, so protocol buffer parsers cannot determine where a message ends on their own. The easiest way to solve this problem is to write the size of each message before you write the message itself. When you read the messages back in, you read the size, then read the bytes into a separate buffer, then parse from that buffer. (If you want to avoid copying bytes to a separate buffer, check out the