关于编组的好例子、文章和书籍
在为基于智能卡的加密狗开发软件保护库时,我意识到我需要在客户端应用程序和加密狗内的代码之间来回传输一些树状数据结构。
那么,在使用 Web 服务时,XML-RPC 或 JSON-RPC 等技术是值得考虑的合理方法。然而,智能卡等嵌入式设备的情况并非如此。您需要使用一些二进制格式来优化内存使用并获得良好的性能。
我想我需要的是实现一些二进制数据封送算法。我不喜欢重新发明整个轮子的想法,而且我确信有关于此类编组问题的很棒的书籍、文章和示例。
你会推荐什么?
UPD。我在 Linux 上使用 C 和 C++,但问题是关于一般编组算法的信息。
While working on a software protection library for smart card based dongle I realized I need to transfer some tree-like data structures back and forth between client application and code inside the dongle.
Well, when working with web services the technologies like XML-RPC or JSON-RPC are reasonable way to consider. However, that is not the case with embedded devices like smart cards. You need to use some binary formats to optimize memory usage and to achieve good performance.
I guess what I need is to implement some binary data marshaling algorithm. I don't like the idea of reinventing the whole wheel and I pretty sure there are great books, articles and examples on marshalling issues like these.
What would you recommend?
UPD. I am using C and C++ on Linux, but the question is about info on marshalling algorithms in general.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以将 ASN.1 视为通用序列化解决方案。
有免费书籍和免费实现:asn1c, a2c,snacc。
但 ASN.1 是一个巨大的。更简单的 protobuf 或 xdr 足以满足您的任务。
You can look at ASN.1 as a general serialization solution.
There are free books and and free implementations: asn1c, a2c, snacc.
But ASN.1 is a huge. Simpler protobuf or xdr can be good enough for your task.
Google 的 Protobuf
首先,我要区分封送处理和 RPC(使用封送处理)。 Google Protobuf 无疑是网络编组的最佳解决方案。它占用空间极小,并且能够以闪电般的速度进行编码/解码。
如果您仍然对如何实现高效封送处理感兴趣,请查看protobuf 编码<的文档/a>.
编码页面的一个示例是 Varint。 Varint 是 protobuf 以二进制格式编码无符号整数的方式。 Varint 针对小数量进行了优化。例如,1 仅在线路上使用一个字节,而 300 使用两个字节。
当然,protobuf 设计者意识到我们经常使用整数作为位掩码等。因此他们还提供了始终为四个字节的整数数据类型(这样设置了 msb 位的掩码不会消耗额外的空间)。
还有充足的文档介绍如何使用 protobuf 实现 RPC。
Google's Protobuf
To start I'm differentiating between marshaling and RPC (which uses marshaling). Google Protobuf is hands down the best solution for marshaling over a network. It has a minimal footprint and encodes/decodes at lightning speed.
If you're still interested in how to implement efficient marshaling checkout the documentation for protobuf encoding.
One example from the encoding page is varint. Varint is how protobuf encodes unsigned integers in binary format. Varint is optimized to for small numbers. eg 1 only uses one byte on the wire while 300 uses two bytes.
Of course the protobuf designers realized that often we use integers as bit masks, etc. So they also provide an integer data type that is always four bytes (that way masks with the msb bits set don't consume extra space).
There is also ample documentation on how to implement RPC with protobufs.
您可能还想查看 Messagepack (http://msgpack.org)。它声称比 Protobuf 快 4 倍。与 Protobuf 相比,该库还支持继承。
You might also want to have a look at Messagepack (http://msgpack.org). It claims to be up to 4 times faster than Protobuf. Also in contrast to Protobuf, this library supports inheritance.
关于您的目标平台/语言的问题,没有太多上下文......但是!
最流行的是(是?)DCOM 和 CORBA。有嵌入式 CORBA .....您可以使用(ACE TAO 库)中的 TAO 之类的东西
,但如果规模相当小,您可以自己序列化它,要记住的主要事情是对序列化格式进行版本控制,以便您可以更改它并支持旧版本(如果这是您项目中的一个问题)
There's not a lot of context in your question about what platform / language you are targetting.... however!
The most popular ones were (are?) DCOM and CORBA. There is embedded CORBA..... you can use something like TAO from the (ACE TAO libraries)
but if this is reasonably small scale, you can just serialize it yourself, main thing to remember is to version the serialization format so you can change it and support legacy versions (if thats a concern in your project)
序列化/编组和树状数据结构在一起听起来是一个很大的问题。以下是我将如何开始解决该问题的一些方面:
显然一些像 google protobuf 这样的库可以提供帮助......
serialisation/marshalling and tree like data structures together sounds like quite big problem. Here's some aspects of how I would start solving it:
Obviously some libs like the google protobuf can help...
您可能会考虑使用 Thrift。
You might consider going with Thrift.