Google 协议缓冲区和 stl 向量、映射和 boost 共享指针
谷歌协议缓冲区是否支持 stl 向量、映射和 boost 共享指针?我有一些对象大量使用 stl 容器
,例如 maps
、vectors
以及 boost::shared_ptr
。我想使用谷歌协议缓冲区将这些对象通过网络序列化到不同的机器。
我想知道 google protobuf 支持这些容器吗?另外,如果我使用 apache thrift 来代替,会更好吗?我只需要序列化/反序列化数据,不需要 apache thrift 提供的网络传输。另外 apache thrift 没有适当的文档也让我望而却步。
Does google protocol buffers support stl vectors, maps and boost shared pointers? I have some objects that make heavy use of stl containers
like maps
, vectors
and also boost::shared_ptr
. I want to use google protocol buffers to serialize these objects across the network to different machines.
I want to know does google protobuf support these containers? Also if I use apache thrift
instead, will it be better? I only need to serialize/de-serialize data and don't need the network transport that apache thrift offers. Also apache thrift not having proper documentation puts me off.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Protocol buffers直接处理少量的构造;向量很好地映射到“重复”元素类型,但是在 C++ 中如何呈现它是通过“add”方法 - 你不(据我所知)只是给它一个向量。有关详细信息,请参阅此处的“重复嵌入消息字段” 。
重新映射;没有内置的机制,但键/值对很容易在 .proto 中表示(通常键 = 1,值 = 2),然后通过“重复”进行处理。
在序列化文件中,shared_ptr本身似乎没有什么意义。但是对象可以(大概)作为消息进行处理。
请注意,在 google C++ 版本中,生成了 DTO 层,因此您可能需要在它们和任何现有对象模型之间进行映射。这通常是非常微不足道的。
对于某些语言/平台,存在针对现有对象模型的 protobuf 变体。
(抱歉,我无法评论 thrift - 我对它不熟悉)
Protocol buffers directly handles an intentionally small number of constructs; vectors map nicely to the "repeated" element type, but how this is presented in C++ is via "add" methods - you don't (AFAIK) just hand it a vector. See "Repeated Embedded Message Fields" here for more info.
Re maps; there is no inbuilt mechanism for that, but a key/value pair is easily represented in .proto (typically key = 1, value = 2) and then handled via "repeated".
A shared_ptr itself would seem to have little meaning in a serialized file. But the object may be handled (presumably) as a message.
Note that in the google C++ version the DTO layer is generated, so you may need to map between them and any existing object model. This is usually pretty trivial.
For some languages/platforms there are protobuf variants that work against existing object models.
(sorry, I can't comment on thrift - I'm not familiar with it)