是否可以使用 protobuf-net Serializer 并同时使用相应的 *.proto 文件?
我有一个 .NET 类型,它既不属于 ProtoContract 也不属于 DataContract。此外,并非其所有状态都需要原型序列化。 我可以为其定义一个 .proto 文件,但同时使用某种序列化程序来序列化它,就像它归因于 ProtoContract 一样吗?
谢谢。
I have a .NET type, which is attributed with neither ProtoContract nor DataContract. In addition, not all of its state need to be proto-serialized.
Can I define a .proto file for it, but at the same time use some kind of a Serializer to serialize it as though it is attributed with ProtoContract?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为第三个选项,可以使用
[XmlType]
和[XmlElement(Order=n)]
...但我不认为这就是您的意思;p在“v2”中,这确实是可能的。您不需要定义 .proto - 您可以简单地告诉它在运行时做什么,例如:
现在将
model
存储在某处(并重新使用它),然后使用model .Serialize(...)
和model.Deserialize(...)
。上面配置SomeType
序列化.Foo
(作为字段 1)、.Bar
(作为字段 2)和.Blip(如字段 3)。当然,还有更多方法可以实现更细粒度的控制。
它将生成(首先需要)一个序列化器(通过 IL 发出,所以非常快),该序列化器可以按预期与您的类型一起使用。
有一个可下载的“v2”dll,但它需要更新 - 我在过去几周内做了很多修复。今天晚些时候我将尝试刷新这个 dll,或者您也可以从代码构建。
As a third option,
[XmlType]
and[XmlElement(Order=n)]
can be used... but I don't think that is what you mean ;pIn "v2", this is indeed possible. You don't need to define a .proto - you can simply tell it what to do at runtime, for example:
now store
model
somewhere (and re-use it), and usemodel.Serialize(...)
andmodel.Deserialize(...)
. The above configuresSomeType
to serialize.Foo
(as field 1),.Bar
(as field 2) and.Blip
(as field 3). There are of course many more ways of doing this for more fine-grained control.It will generate (as first needed) a serializer (via IL emit, so very fast) that works with your types as expected.
There is a downloadable "v2" dll, but it needs updating - I have done a lot of fixes in the last few weeks. I will try to refresh this dll later today, or you can build from code.