【问题标题】:Raw proto representation of protobuf-net (De)SerializeWithLengthPrefixprotobuf-net (De)SerializeWithLengthPrefix 的原始原型表示
【发布时间】:2015-12-10 07:55:14
【问题描述】:

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

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

例如,给定一条消息:

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

根据this Google 分组线程,@marc-gravell 说“...SerializeWithLengthPrefix 方法,默认情况下,旨在以一种有效的 protobuf 流的方式表示数据 - 特别是,好像它只是父对象或列表的成员..."

当使用

序列化时,“父对象或列表”在原始 proto 定义中会是什么样子
Serializer.NonGeneric.SerializeWithLengthPrefix(<stream>, new KeyValuePair { Name = "foo", Value = "Bar" }, PrefixStyle.Base128, <unique_message_id>)

?

提前感谢您的帮助!

【问题讨论】:

    标签: c# protocol-buffers protobuf-net


    【解决方案1】:
    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]
    

    【讨论】:

    • 完美。这正是我所需要的。谢谢!
    猜你喜欢
    • 2012-01-25
    • 1970-01-01
    • 1970-01-01
    • 2022-10-14
    • 2014-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多