Serialize/Deserialize binary data in clojure with an api similar
to pointer casting in C
.
[fctorial/parse_struct "0.8.0"]
fctorial/parse_struct {:mvn/version "0.8.0"}
compile 'fctorial:parse_struct:0.8.0'
<dependency>
<groupId>fctorial</groupId>
<artifactId>parse_struct</artifactId>
<version>0.8.0</version>
</dependency>
(ns examples
(:require [parse_struct.core :refer [serialize deserialize type-size]]
[parse_struct.common_types :as ct]))
(declare byte-seq)
(deserialize ct/i16 byte-seq)
; short integer
(deserialize {:type :array
:len 20
:element ct/u32be}
byte-seq)
; seq of big endian unsigned integers (long if they're too big, since java doesn't have unsigned. Large longs are stored in bigint)
(deserialize {:type :struct
:definition [[:a ct/u32]
(ct/padding 2)
[:b ct/i32]
[:c {:type :string
:bytes 8}]]}
byte-seq)
; a struct
See wiki for full documentation.
See this repo for examples that parse various file formats (elf
, zbi
, multiboot
).
You'll have to run this command to compile java classes:
javac -cp $(cat .cpcache/$(ls .cpcache/*.cp | head -n 1)) src/clojure/lang/* -d classes
You'll need to have gcc
installed to run tests.
clojure -A:test-setup
clojure -A:dump-server
# in other window
clojure -A:test
Can you improve this documentation? These fine people already did:
Sagar Tiwari & Ertuğrul ÇetinEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close