使用 JPA 的协议缓冲区

发布于 2024-07-27 04:23:09 字数 456 浏览 2 评论 0原文

我目前正在构建一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

甜`诱少女 2024-08-03 04:23:09

Java Protocol Buffers API 想要生成类。 所以看起来很难对它们进行注释。 相反,您可以从自己的 XML“架构”开始,然后使用 XSLT 样式表:

  1. 创建 .proto 文件
  2. 创建 JPA 实体映射 XML 文件。

然后您可以将 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:

  1. Creates a .proto file
  2. Creates a JPA entity mapping XML file.

You could then use the google generated files with JPA.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文