I'm looking for a way to efficiently serialize Clojure objects into a binary format - i.e. not just doing the classic print and read text serialization.
i.e. I want to do something like:
(def orig-data {:name "Data Object"
:data (get-big-java-array)
:other (get-clojure-data-stuff)})
(def binary (serialize orig-data))
;; here "binary" is a raw binary form, e.g. a Java byte array
;; so it can be persisted in key/value store or sent over network etc.
;; now check it works!
(def new-data (deserialize binary))
(= new-data orig-data)
=> true
The motivation is that I have some large data structures that contain a significant amount of binary data (in Java arrays), and I want to avoid the overhead of converting these all to text and back again. In addition, I'm trying to keep the format compact in order to minimise network bandwidth usage.
Specific features I'd like to have:
- Lightweight, pure-Java implementation
- Support all of Clojure's standard data structures as well as all Java primitives, arrays etc.
- No need for extra build steps / configuration files - I'd rather it just worked "out of the box"
- Good performance both in terms of processing time required
- Compactness in terms of binary encoded representation
What's the best / standard approach to doing this in Clojure?