2
它看起來像Int64有一個0的編碼問題。其他值爲Int64 ok。protobuf.net不是序列化零
[ProtoMember(3)] private readonly Int64 _intValue
被反序列化Int64.MinValue
任何想法?
我確認了這個錯誤。如果_Val == 0
[ProtoContract]
class VerySimple
{
[ProtoMember(1)]
private readonly Int64 _val = Int64.MinValue;
public VerySimple(long val)
{
_val = val;
}
public long Val
{
get { return _val; }
}
public VerySimple()
{
}
}
測試失敗
[測試]
public void TestProtobufEncodingSimple()
{
//OK
{
MemoryStream stream = new MemoryStream();
Serializer.Serialize(stream, new VerySimple(1));
stream.Seek(0, SeekOrigin.Begin);
VerySimple reloaded = Serializer.Deserialize<VerySimple>(stream);
Assert.AreEqual(reloaded.Val, 1L);
}
//KO
{
MemoryStream stream = new MemoryStream();
Serializer.Serialize(stream, new VerySimple(0));
stream.Seek(0, SeekOrigin.Begin);
VerySimple reloaded = Serializer.Deserialize<VerySimple>(stream);
Assert.AreEqual(reloaded.Val, 0L);
}
}