Is ANTLR an appropriate tool to serialize/deserialize a binary data format?
Asked Answered
J

3

10

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

Jannelle answered 5/2, 2009 at 17:47 Comment(0)
U
10

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.

Usurpation answered 5/2, 2009 at 18:3 Comment(1)
The subject of standards with 500 pages (?!) comes up very often on the ANTLR mailing list? The machine overhead would have to be large to outweigh the benefit of using a great parser generator to correctly implement the standard.Eyepiece
T
16

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.

Thrombo answered 11/4, 2009 at 15:44 Comment(2)
I had not heard of Ragel before. It sounds interesting and may work for my problem. Thanks.Jannelle
If you need recursive rules, you may run into some pain with Ragel. If not, it may be a great tool for your job.Eyepiece
U
10

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.

Usurpation answered 5/2, 2009 at 18:3 Comment(1)
The subject of standards with 500 pages (?!) comes up very often on the ANTLR mailing list? The machine overhead would have to be large to outweigh the benefit of using a great parser generator to correctly implement the standard.Eyepiece
L
4

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.

Lampoon answered 5/2, 2009 at 17:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.