使用 JPA 的协议缓冲区
我目前正在构建一个 P2P 系统,该系统使用协议缓冲区进行对等点之间的所有通信。 系统还有一些集中部分,对等点与服务器进行通信。 服务器使用 JPA 来存储有关对等点的数据。
因此,本质上客户端的数据位于 Protocol Buffers 消息中,服务器的数据位于 JPA 实体中。 因此我的问题是是否有办法在它们之间自动转换?
我正在寻找的是:
- 来自 .protos-files 的 JPA 实体生成器或
- 来自 JPA 实体的 .protos-文件生成器以及
- 某种在运行时在它们之间自动转换的方法,这样我就不必创建代码为每个新班级手动执行此操作。
理想情况下,您可以更进一步,让它们都是相同的类(即带有 JPA 注释的协议缓冲区),但如果无法实现,则上述方法也可以。
这是否已完成?如果没有,您认为在合理的时间内实施是否可行?
I'm currently building a P2P-system which uses Protocol Buffers for all communication between the peers. There's also a some centralized parts of the system where the peers communicate with a server. The server uses JPA to store the data it has about the peers.
So essentially the clients has its data in Protocol Buffers-messages and the server in JPA-entities. My question is therefore if there's a way to automatically convert between them?
What I'm looking for is:
- A generator of JPA-entities from .protos-files OR
- A generator of .protos-files from JPA-entities AND
- Some way to automatically convert between them at runtime so I don't have create the code to do it manually for every new class.
Ideally you could take it one step further and have them both be the same classes (i.e. Protocol Buffers with JPA annotations) but if that's not attainable the above would work as well.
Has this been done and if not do you think it's feasible to implement in a reasonable amount of time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Java Protocol Buffers API 想要生成类。 所以看起来很难对它们进行注释。 相反,您可以从自己的 XML“架构”开始,然后使用 XSLT 样式表:
然后您可以将 google 生成的文件与 JPA 一起使用。
The Java Protocol Buffers API wants to generate the classes. So it seems like it would be hard to then annotate those. Instead, you could start with your own XML "schema", and then have XSLT stylesheets that:
You could then use the google generated files with JPA.