접두사 스타일을 고정으로 전환 한 후에는 사제화가 실패합니다

StackOverflow https://stackoverflow.com/questions/1477526

  •  16-09-2019
  •  | 
  •  

문제

사용하고있는 커뮤니케이션 라이브러리를위한 테스트 스위트가 있습니다. protobuf-net 괜찮아요. 모든 테스트가 통과됩니다. 그러나 접두사 스타일을 Base128에서 Fixed32로 변경하면 사막화가 실패합니다.

내가받는 예외 TryDeserializeWithLengthPrefix 기능은 다음과 같습니다.


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

내가 간단하게 접두사 스타일을 유지하면 모든 것이 작동합니다. Base128 메시지를 직렬화하고 사망 할 때.

무슨 일이 일어나고 있는지 아는 사람이 있습니까?

도움이 되었습니까?

해결책

hohum, yup는 버그처럼 보입니다 (이제 기록되었습니다); 아래의 반복 가능한 예. 기차에서 (곧) 고칠 수 있는지 볼 것입니다. 죄송합니다.

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