二进制流解析库对于C [英] Binary streams parsing library for C

查看:293
本文介绍了二进制流解析库对于C的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能不能劝一个成熟的二进制流解析库对于C?这将是很好,如果将它作为声明为C允许。

Could you advise a proven binary stream parsing library for C? It will be nice if it will be as declarative as C allows.

我需要它的二进制协议解析和它所描述相当复杂协议的正式规范,这就是为什么我希望它尽可能多的声明越好。就像是
Haskell的Data.Binary.Get将是巨大的。

I need it for binary protocol parsing and describing the quite complicated protocol by it's formal specification, that's why I want it as much declarative as possible. Something like Haskell's Data.Binary.Get will be great.

我发现binpac,但似乎重量级的,面向C ++的,但该项目是纯粹的C

I've found binpac, but it seems heavyweight and oriented for C++ , but the project is pure C.

例说明我的意思:

parser_t parsers[] = {
  { get_bit,      out_field1, &pkt.field1 }
 ,{ get_bit7,     0,           0          } // skip 7 bits
 ,{ get_word16be, out_field2, &pkt.field2 }
 ,{ 0,            0,           0          } // end
};

// skip
// char *data, char *data_end, 
map_parsers(data, data_end, parsers); // parse stream

UPD。它的优良刚才的顺序读取位,字,对齐,对齐等从内存中快速库。我在上面写上声明前端甚至DSL在我自己的。

UPD. It's fine to have just a fast library for sequential reading bits, words, aligned, unaligned, etc from memory. I may write declarative frontend or even DSL on my own.

推荐答案

有的 PADS从尼斯人在AT&放的;吨。还有 RAGEL 的可用于同样的事情。我没有使用,也可以自己,但发现它们的存在暗示在此页面

There's PADS from the nice people at AT&T. There's also RAGEL which can be used for the same thing. I've not used either myself, but found hints of their existence on this page.

PADS看起来像一个类似的想法,从目标系统和谷歌协议缓冲区的ASN1编译器;你写一个模式文件,然后编译到您选择的源$ C ​​$ c语言。当然不同的是,对于严格定义的二进制编码方案而PADS这两个工作似乎适用于任意的数据流。

PADS looks like a similar idea to the ASN1 compiler from Objective Systems and Google Protocol buffers; you write a schema file, then compile that to the source code language of your choice. The difference of course is that those two work for strictly defined binary encoding schemes whereas PADS seemingly works for arbitrary data streams.

祝你好运!

这篇关于二进制流解析库对于C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆