【发布时间】:2014-09-04 09:43:50
【问题描述】:
我一直在阅读documentation 的 protobuf-net 属性,但我并不精通 protobuf 规范。
我在 MVC 项目中使用它,在反序列化期间,DbGeography 为空。
类
public class Foo
{
[ProtoMember(1)]
public int Id { get; set; }
[ProtoMember(2, AsReference = true)]
public DbGeography Location { get; set; }
}
这就是我的班级目前的样子,我尝试过使用DynamicType 和IsRequired,无论如何都不起作用。我希望有人一直在做类似的事情,而不是试图猜测/混合和匹配。
我在环顾四周时看到的最接近的东西是这个项目,它有一个自定义 reader 和 writer,它使用 protobuf 作为空间数据类型,但它是一个自定义类。
更新
public class Foo
{
[ProtoMember(1)]
public int Id { get; set; }
[ProtoMember(2, DynamicType= true)] //<-- this works
public DbGeography Location { get; set; }
}
但我仍然想知道标记这些成员的最佳方式是什么,例如性能与规模的权衡
更新 2
[ProtoContract]
public class Foo
{
[ProtoMember(1)]
public int Id { get; set; }
public string Address { get; set; }
[ProtoMember(2, AsReference = true)]
public DbGeography Location { get; set; }
[ProtoMember(8, AsReference = true)] //<-- What is the cost of using this for List<Bar>? since im using a non-primitive type
public List<Bar> Bars { get; set; }
}
【问题讨论】:
标签: c# asp.net-mvc serialization protobuf-net