![](/img/trans.png)
[英]What is protobuf-net SerializeWithLengthPrefix tag argument for?
[英]Raw proto representation of protobuf-net (De)SerializeWithLengthPrefix
首先,这是不是重复这个其它问题,请萎靡不振前仔细阅读我的问题。
我需要写出原始原始文件,这些文件与使用Serializer.NonGeneric。(De)Serialize读写的C#(反)序列化消息相匹配。 我目前使用PrefixStyle.Base128,并且希望继续这样做(除非使用PrefixStyle.Fixed32是前进的唯一方法)。
例如,给出一条消息:
message KeyValuePair {
optional string Key = 1;
optional string Value = 2 [default = ""];
}
根据这个 Google群组线程,@ marc-gravell说:“ ... SerializeWithLengthPrefix方法默认情况下旨在以有效的protobuf流方式表示数据-特别是好像它只是父对象的成员一样或列出... ”
当使用序列化时,原始原型定义中的“ 父对象或列表 ”会是什么样子
Serializer.NonGeneric.SerializeWithLengthPrefix(<stream>, new KeyValuePair { Name = "foo", Value = "Bar" }, PrefixStyle.Base128, <unique_message_id>)
?
在此先感谢您的帮助!
message DummyDoesNotExist {
optional KeyValuePair Value = <unique_message_id>;
}
在电线上,则为:
varint: [wire-type: length-prefixed, field: <unique_message_id>] // typically 1 byte
varint: [length] // typically 1 or 2 bytes
[length bytes of KeyValuePair data]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.