ANTLR 是序列化/反序列化二进制数据格式的合适工具吗?

发布于 2024-07-13 15:21:43 字数 399 浏览 9 评论 0原文

我需要读取和写入八位字节流以通过各种网络发送以与智能电表进行通信。 有一个 ANSI 标准 ANSI C12.19 描述了二进制数据格式。 虽然数据格式并不过分复杂,但该标准非常大(500 多页),因为它描述了许多不同的类型。 该标准由 EBNF 语法完整描述。 我正在考虑利用 ANTLR 来读取 EBNF 语法或其修改版本,并创建可以读写八位字节流的 C# 类。

这是 ANTLR 的好用吗?

如果是这样,我需要做什么才能使用 ANTLR 3.1? 通过搜索新闻组档案,我似乎需要实现一个可以读取字节而不是字符的新流。 这就是全部还是我还必须实现 Lexer 衍生物?

如果 ANTLR 可以帮助我读取/解析流,它也可以帮助我写入流吗?

谢谢。

丹菲努卡内

I need to read and write octet streams to send over various networks to communicate with smart electric meters. There is an ANSI standard, ANSI C12.19, that describes the binary data format. While the data format is not overly complex the standard is very large (500+ pages) in that it describes many distinct types. The standard is fully described by an EBNF grammar. I am considering utilizing ANTLR to read the EBNF grammar or a modified version of it and create C# classes that can read and write the octet stream.

Is this a good use of ANTLR?

If so, what do I need to do to be able to utilize ANTLR 3.1? From searching the newsgroup archives it seems like I need to implement a new stream that can read bytes instead of characters. Is that all or would I have to implement a Lexer derivative as well?

If ANTLR can help me read/parse the stream can it also help me write the stream?

Thanks.

dan finucane

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

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

发布评论

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

评论(3

殊姿 2024-07-20 15:21:44

在我看来,掌握语法会给你带来巨大的帮助。

ANTLR 3.1 具有与解析/词法分析分离的 StringTemplate 和代码生成功能,因此您可以通过这种方式分解问题。

对我来说似乎是一个胜利者,值得尝试。

It seems to me that having a grammar gives you a tremendous leg up.

ANTLR 3.1 has StringTemplate and code generation features that are separate from the parsing/lexing, so you can decompose the problem that way.

Seems like a winner to me, worth trying.

哭了丶谁疼 2024-07-20 15:21:43

您可以看看 Ragel。 它是一个状态机编译器/词法分析器,对于实现在线协议非常有用。 我读过报告说它生成的代码非常快。 如果你不需要解析器和模板引擎,ragel 的开销比 ANTLR 更少。 如果您需要成熟的解析器、AST 和良好的模板引擎支持,ANTLR 可能是更好的选择。

You might take a look at Ragel. It is a state machine compiler/lexer that is useful for implementing on-the-wire protocols. I have read reports that it generates very fast code. If you don't need a parser and template engine, ragel has less overhead than ANTLR. If you need a full-blown parser, AST, and nice template engine support, ANTLR might be a better choice.

半﹌身腐败 2024-07-20 15:21:43

这个主题不时出现在 ANTLR 邮件列表中。 答案通常是否定的,因为二进制文件格式非常规则,不值得花费这些开销。

This subject comes up from time to time on the ANTLR mailing list. The answer is usually no, because binary file formats are very regular and it's just not worth the overhead.

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