簡體   English   中英

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

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM