看起来 0 作为 Int64 存在编码问题。其他值如 Int64 ok。
[ProtoMember(3)] private readonly Int64 _intValue
被反序列化为 Int64.MinValue
任何想法?
我确认错误。如果 _val == 0,此类将无法正确序列化
[原合同]
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);
}
}