通过
违约
protobuf(google spec,而不是proobuf net)的设计允许您将连续的消息视为单个对象的一部分,也就是说,您可以通过连接向消息添加字段,这基本上就是您在这里所做的。每个顶级对象(默认情况下)没有
任何
与下一个对象的分离。
要让它将它们视为不同的对象,请查看
*WithLengthPrefix
方法(或者您可以使用
IEnumerable<T>
版本-可能
DeserializeItems
;还请注意,如果您为其提供类似要序列化的列表的内容,它将自动应用长度前缀;例如:
基本上:
Serializer.SerializeWithLengthPrefix(stream, postA1, PrefixStyle.Base128, 1);
Serializer.SerializeWithLengthPrefix(stream, postB1, PrefixStyle.Base128, 1);
stream.Position = 0;
var postA2 = Serializer.DeserializeWithLengthPrefix<Post>(stream,
PrefixStyle.Base128, 1);
var postB2 = Serializer.DeserializeWithLengthPrefix<Post>(stream,
PrefixStyle.Base128, 1);