关于编组的好例子、文章和书籍

发布于 2024-11-14 17:23:06 字数 327 浏览 2 评论 0原文

在为基于智能卡的加密狗开发软件保护库时,我意识到我需要在客户端应用程序和加密狗内的代码之间来回传输一些树状数据结构。

那么,在使用 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 技术交流群。

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

发布评论

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

评论(6

回忆凄美了谁 2024-11-21 17:23:06

您可以将 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.

星星的轨迹 2024-11-21 17:23:06

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.

十秒萌定你 2024-11-21 17:23:06

您可能还想查看 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.

夜司空 2024-11-21 17:23:06

关于您的目标平台/语言的问题,没有太多上下文......但是!

最流行的是(是?)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)

北恋 2024-11-21 17:23:06

序列化/编组和树状数据结构在一起听起来是一个很大的问题。以下是我将如何开始解决该问题的一些方面:

  1. 考虑数据编码。 4个字节用于int传输还是ascii传输?
  2. 考虑是否需要传输整个数据或只是在两个树数据结构之间同步,
  3. 每一位数据都需要知道它在树结构中的位置。识别数据位对于解决这个问题有很大帮助。
  4. 考虑什么需要转移?
    • 只是树节点内的数据?
    • 树结构发生变化吗?
    • 整棵树?
    • 数据的位置/ID?
  5. 识别数据
    • 使用从根到树节点的路径?
    • 使用子树?
    • 使用简单的数据节点
    • 识别树节点内的元素?
  6. 考虑如何发布树中的数据
    • 也许可以编写给出所有数据的接口?
    • 你能用算法递归地遍历所有数据
    • 数据中是否存在无法轻易传输的指针?

显然一些像 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:

  1. consider encoding of the data. 4 bytes for int transfer or transfer as ascii?
  2. consider if you need to transfer whole data or just sync between two tree data structures
  3. every bit of data needs to know where it is in the tree structure. Identifying data bits will help quite much in this problem.
  4. consider what needs to be transferred?
    • just data inside the tree nodes?
    • changes to the tree structure?
    • the whole tree?
    • location/id of the data?
  5. identifying data
    • use paths from root to the tree node?
    • use subtrees?
    • use simple data nodes
    • identifying elements inside tree node?
  6. consider how to publish the data in the tree
    • maybe write interface that gives out all the data?
    • can you recursively go through all the data with an algorithm
    • is there pointers inside the data which cannot be transferred easily?

Obviously some libs like the google protobuf can help...

画▽骨i 2024-11-21 17:23:06

您可能会考虑使用 Thrift

You might consider going with Thrift.

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