protobuf-net 与 C++ 通信

发布于 2024-08-16 02:03:33 字数 294 浏览 4 评论 0原文

我正在研究 protobuf-net 来实现各种消息格式,我特别喜欢基于契约的方法,因为我不必弄乱 proto 编译器。我找不到相关信息的一件事是,这是否会导致跨平台工作变得困难?有一些 C++ 应用程序需要能够解析 PB 数据,虽然我了解 protobuf-net 序列化为 PB 标准格式,但如果我使用契约方法而不是 proto 文件,C++ 端如何解析数据?

我可以(应该?)为 C++ 需要理解数据的(极少数)情况编写一个单独的原型文件吗?如果是这样,我到底如何知道从 proto 文件生成的 C++ 类将与无 proto 文件 C# 端的数据匹配?

I'm looking at protobuf-net for implementing various messaging formats, and I particularly like the contract-based approach as I don't have to mess with the proto compiler. one thing I couldn't quite find information on is, does this make it difficult to work cross-platform? there are a few C++ apps that would need to be able to parse PB data, and while I understand that protobuf-net serializes to the PB standard format, if I use the contract approach and not a proto file, how does the C++ side parse the data?

can (should?) I write a separate proto file for the (very few) cases where C++ needs to understand the data? and if so, how exactly do I know that the C++ class generated from the proto file is going to match the data from the no-proto-file C# side?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

岁月静好 2024-08-23 02:03:33

是的,理论上至少它们应该在二进制级别匹配,但您可能希望将自己限制为仅映射到“.proto”的类型 - 因此避免诸如 DateTime、继承 ([ProtoInclude]) 等。这还有一个优点,您应该能够使用:

string proto = Serializer.GetProto<YourType>();

获取 .proto;它 (GetProto) 不是 100%,但它适用于基本类型。但最终的答案是“测试和调整”;也许从一开始就设计互操作性——即尽早测试。

Yes, in theory at least they should match at the binary level, but you might want to limit yourself to types that map simply to ".proto" - so avoid things like DateTime, inheritance ([ProtoInclude]), etc. This also has the advantage that you should be able to use:

string proto = Serializer.GetProto<YourType>();

to get the .proto; it (GetProto) isn't 100%, but it works for basic types. But ultimately, the answer is "testing and tweaking"; perhaps design for interop from the outset - i.e. test this early.

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