Protobuf-net:ProtoMemberAttribute.AsReference 和 ProtoContract.AsReferenceDefault 有什么区别
Protbuf-net: what is the deference between ProtoMemberAttribute.AsReference and ProtoContract.AsReferenceDefault
ProtoContract
属性 - AsReferenceDefault
和 ProtoMemberAttribute
属性 AsReference
.
有什么区别
根据wiki:
AsReference
- enables reference tracking of the sub-object; this uses
a very different serialization layout, but will only serialize that
object once (giving it a unique token for referencing). This allows
full-graph support for otherwise cyclic graphs. This can also be used
to great effect to efficiently store common strings that are otherwise
repeated many times in the data
但它与 ProtoContract
属性 有什么关系:AsReferenceDefault
?
例如,如果将 AsReferenceDefault
设置为 true 是否意味着不再需要 ProtoMemberAttribute
属性 AsReference
?
是的,如果 AsReferenceDefault
应用于 class,即使相应的 属性 没有在 ProtoMemberAttribute
上声明 AsReference
,它也会始终序列化为引用.
理想为你的大class,你确定对象很大,最好序列化一次作为参考,所以你可以标记为AsReferenceDefault
。
AsReference
旨在处理引用序列化,即使它不是您自己的 class,例如 String
.
ProtoContract
属性 - AsReferenceDefault
和 ProtoMemberAttribute
属性 AsReference
.
根据wiki:
AsReference
- enables reference tracking of the sub-object; this uses a very different serialization layout, but will only serialize that object once (giving it a unique token for referencing). This allows full-graph support for otherwise cyclic graphs. This can also be used to great effect to efficiently store common strings that are otherwise repeated many times in the data
但它与 ProtoContract
属性 有什么关系:AsReferenceDefault
?
例如,如果将 AsReferenceDefault
设置为 true 是否意味着不再需要 ProtoMemberAttribute
属性 AsReference
?
是的,如果 AsReferenceDefault
应用于 class,即使相应的 属性 没有在 ProtoMemberAttribute
上声明 AsReference
,它也会始终序列化为引用.
理想为你的大class,你确定对象很大,最好序列化一次作为参考,所以你可以标记为AsReferenceDefault
。
AsReference
旨在处理引用序列化,即使它不是您自己的 class,例如 String
.