質問

使用している通信ライブラリ用のテストスイートを使用しています protobuf-net それは大丈夫です。すべてのテストが渡されます。ただし、プレフィックススタイルをbase128からsixed32に変更すると、敏arializationは失敗します。

私が受け取る例外 TryDeserializeWithLengthPrefix 機能は次のとおりです。


System.ArgumentNullException was caught
  Message="Value cannot be null.\r\nParameter name: type"
  Source="protobuf-net"
  ParamName="type"

メッセージをシリアル化してゆるくするときに、prefixStyle.base128を簡単に保持する場合、すべてが機能します。

誰もが何が起こっているのか知っていますか?

役に立ちましたか?

解決

ホーム、うん、バグのように見えます(記録されました);以下の繰り返しの例。電車で修正できるかどうかを確認します(まもなく)。申し訳ありません '試合:

using System;
using System.IO;
using ProtoBuf;
[ProtoContract]
public class Strange // test entity
{
    [ProtoMember(1)]
    public string Foo { get; set; } // test prop
    [ProtoMember(2)]
    public int Bar { get; set; } // test prop

    static void Main() {
        var original = new Strange { Foo = "abc", Bar = 123 };
        // serialize and deserialize with base-128
        using (MemoryStream ms = new MemoryStream()) {
            Serializer.SerializeWithLengthPrefix(ms, original, PrefixStyle.Base128,1);
            ms.Position = 0;
            object obj;
            Serializer.NonGeneric.TryDeserializeWithLengthPrefix(ms,
                PrefixStyle.Base128, i => typeof(Strange),out obj);
            var clone = (Strange)obj;
            Console.WriteLine("Foo via Base128: " + clone.Foo); // works fine
            Console.WriteLine("Bar via Base128: " + clone.Bar);
        }
        // serialize and deserialize with fixed-32
        using (MemoryStream ms = new MemoryStream())
        {
            Serializer.SerializeWithLengthPrefix(ms, original, PrefixStyle.Fixed32,1);
            ms.Position = 0;
            object obj;
            // BOOM here; oh how embarrassing
            Serializer.NonGeneric.TryDeserializeWithLengthPrefix(ms,
                PrefixStyle.Fixed32, i => typeof(Strange), out obj);
            var clone = (Strange)obj;
            Console.WriteLine("Foo via Fixed32: " + clone.Foo);
            Console.WriteLine("Bar via Fixed32: " + clone.Bar);
        }
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top