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

Raw proto representation of protobuf-net (De)SerializeWithLengthPrefix

首先,这不是 this 其他问题的重复,所以请在标记之前完整阅读我的问题。

我需要写出与使用 Serializer.NonGeneric.(De)Serialize 读取和写入的 C#(反)序列化消息相匹配的原始原型文件。我目前使用 PrefixStyle.Base128 并希望继续这样做(除非使用 PrefixStyle.Fixed32 是唯一的前进方向)。

例如,给定一条消息:

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

根据 this 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]