序列化 / 二进制格式

(require '[clojure.edn :as edn])

(defrecord Data [text num arr])

(def data (->Data "Hello" 3.14 [2 5 7]))

; the core has no binary serializer; EDN is the
; native format of Clojure data
; Encoding Binary Data
(def data-b (.getBytes (pr-str (into {} data)) "UTF-8"))

; Decoding Binary Data
(def data2 (map->Data
             (edn/read-string (String. data-b "UTF-8"))))
; data2 text is "Hello"

(println "data-b size is" (count data-b))
(println "data2 is" data2)