简体   繁体   English

protobuf-net(De)SerializeWithLengthPrefix的原始原型表示形式

[英]Raw proto representation of protobuf-net (De)SerializeWithLengthPrefix

First of all, this is NOT a duplicate of this other question so please read my question fully before flagging it. 首先,这是不是重复这个其它问题,请萎靡不振前仔细阅读我的问题。

I need to write out raw proto files that match up with C# (de)serialized messages read and written using Serializer.NonGeneric.(De)Serialize. 我需要写出原始原始文件,这些文件与使用Serializer.NonGeneric。(De)Serialize读写的C#(反)序列化消息相匹配。 I currently use PrefixStyle.Base128 and would like to continue doing so (unless using PrefixStyle.Fixed32 is the only way forward). 我目前使用PrefixStyle.Base128,并且希望继续这样做(除非使用PrefixStyle.Fixed32是前进的唯一方法)。

For example, given a message: 例如,给出一条消息:

message KeyValuePair {
   optional string Key = 1;
   optional string Value = 2 [default = ""];
}

According to this Google groups thread, @marc-gravell says " ...SerializeWithLengthPrefix method, by default, aims to represent data in a way that is a valid protobuf stream - in particular, as though it were simply a member of a parent object or list... " 根据这个 Google群组线程,@ marc-gravell说:“ ... SerializeWithLengthPrefix方法默认情况下旨在以有效的protobuf流方式表示数据-特别是好像它只是父对象的成员一样或列出...

What would the " parent object or list " look like in a raw proto definition when serialized using 当使用序列化时,原始原型定义中的“ 父对象或列表 ”会是什么样子

Serializer.NonGeneric.SerializeWithLengthPrefix(<stream>, new KeyValuePair { Name = "foo", Value = "Bar" }, PrefixStyle.Base128, <unique_message_id>)

?

Thanks in advance for any help! 在此先感谢您的帮助!

message DummyDoesNotExist {
    optional KeyValuePair Value = <unique_message_id>;
}

On the wire, this is then: 在电线上,则为:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM