Josh Marinacci has a blog post concerning using OMeta to parse binary data and while there was not a complete cut/paste of all the Javascript code needed to run it in OMeta/JS, I saved his grammar for review as I was working on binary parsing using an OMeta that was using C# as the host language. Recently I give the link of his posting to someone else, but turns out Josh’s blog was offline (crashed?). (Update; Appears his blog is working again, so you can refer to the link below for his original post)
So I dug up what I had and whipped up an OMeta/JS example for a complete working proof of concept and here are the results. I am not a JavaScript kind-of-guy, so be nice regarding the code. ;-)
Note: The W3 spec has 18 chunks that can be defined in PNG files and I added ‘iTXt’ to Josh’s original as the PNG I was using as an example had a large chunk of XML data in it, but a lot of chunks are still missing as this is just a proof of concept and the original binaries that I was parsing were not PNGs, but custom AMF2 byte streams that were getting converted to objects ‘on the 'fly’ via IlGenerator in C#…
Original PNG parse concept from Josh is at the following link assuming he gets the blog working: http://joshondesign.com/2013/03/18/ConciseComputing
And his related email thread on vpri.org : http://vpri.org/pipermail/ometa/2013-March/000524.html
So if you load up OMeta/JS, the complete grammar and Javascript functions needed is shown below. Just open up your JS console before doing a “Do It” so you can see the chunk information found in the PNG and interact with the final object.
Here is an example console output of parsing a PNG file via this OMeta/JS script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
This is a working example of parsing binary data parsing in Ometa/JS.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|