Binary data parsing

Nov 21, 2013 at 2:46 PM
Can Irony be used for parsing a stream of binary data?
For instance I'm getting binary data as:
<HeaderId><message or collection of messages with terminator><terminator>

Depending on HeaderId the message that follows it is in different format.

Based on the data in the stream, I'd like to construct CLR objects and set their properties accordingly. So far I've been doing the manual parsing with a huge nested switch/case statements, which is hard to maintain. I'm wondering if Irony could make it easier.

Nov 21, 2013 at 8:00 PM
theoretically, you can try, but I doubt it's worth the trouble. LALR parser are general facilities to parse regular, hierarchical 'inputs', whatever format it is - so binary parsing is possible. But Irony is heavily geared toward text input.
To try, you can either create a set of terminals that can read binary data (and modify parser/scanner pipeline to accept binary input), or maybe convert binary stream to some kind of text first, and then try to parse it using Irony
Dec 4, 2013 at 6:38 AM
As a non-Irony side note: I had a requirement to parse a binary stream and 'transform' it to objects on the fly (via ILGenerator) and went with an OMeta(PEG) approach as it was a clean way, for me a least, to not build those "huge nested switch/case statements" which another DevOps person had started doing. Maintenance/testing was killing that approach.

Check out:

The PNG parsing example was done in OMeta/JS but it is not 100% complete cut/paste example (I have a working OMeta/JS for it somewhere), but I used the concept in C#, there are several OMeta OSS projects that use C# as the 'host language'. The extended PEG format of OMeta just clicks and works in my head for some reason and my end result with as clean as the PNG grammar in that post. Simple to maintain and extend (IMHO).
Dec 4, 2013 at 2:38 PM
Hey Sushihangover,

Thanks for the explanation. The link you've provided doesn't seem to work. I get "500 TypeError: Cannot call method 'hasNext' of undefined"
Please advise.
Dec 5, 2013 at 4:56 AM
(Codeplex hung three times on trying to post a reply, so I'm trying via their email posting system)

Seems like Josh's blog crashed… try again later I guess.

I dug up his original proof of concept grammar, finished the missing JavaScript functions and made a blog post out of it on my site: Try and that should get you going in the OMeta direction if you are interested.