You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Clojure/ClojureScript library for parsing binary data as easy as it is in C
Rationale
Parsing binary bytes of data in Clojure/ClojureScript is a pain in the butt. This library simulates C structs and pointer arithmetic to allow parsing of binary data in a C like way.
Octet is a similar library for parsing binary data but it is more high level. Translating C code into octet requires more thinking.
Voodoo is design to make it easier to translate C code into Clojure without much cognitive re-mapping.
TODO
ClojureScript support is pending
Sequential everywhere
Voodoo treats byte buffers as squentials. There are functions with names starting with seq-> to convert sequential of bytes into primitive types and vice versa. For example, seq->int and int->seq
(require '[stigmergy.tily :as util])
(let [buffer (util/suck"./person.dat") ;;suck in raw bytes
struct-person [:id:int32:fname [:char20] ;;char and byte are same size so it doesn't matter which you use:lname [:byte20]]
person-size (sizeof struct-person)
person-pt (pointer struct-person buffer)
person-count 3]
(doseq [i (range person-count)
:let [id (person-pt:id) ;;"dereferncing" id field, in C it would be like personPt->id
fname (person-pt:fname)
lname (person-pt:lname)
person {:id (seq->int id)
:fname (->> fname
seq->str)
:lname (->> lname
seq->str)}]]
(prn person)
(person-pt + person-size)))
About
Clojure/ClojureScript library for parsing binary data in a C like way