From c60013f21f326a668ad0c08d192ca812cce91db5 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Wed, 8 May 2013 20:35:22 -0400 Subject: [PATCH] edn serialization --- src/hottub/serialize.clj | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/hottub/serialize.clj diff --git a/src/hottub/serialize.clj b/src/hottub/serialize.clj new file mode 100644 index 0000000..f399914 --- /dev/null +++ b/src/hottub/serialize.clj @@ -0,0 +1,21 @@ +(ns hottub.serialize + (:require [clojure.edn :as edn])) + +(defmethod print-dup clojure.lang.PersistentQueue [o w] + (.append w "#hottub/queue ") + (print-dup (into [] o) w)) + +(defn deserialize-queue [l] + (into clojure.lang.PersistentQueue/EMPTY l)) + +(defn write + ([o] (with-open [w (java.io.StringWriter.)] + (write o w) + (.toString w))) + ([o w] (print-dup o w))) + +(defmulti read class) +(defmethod read String [s] (read (java.io.StringReader. s))) +(defmethod read java.io.Reader [r] + (with-open [pbr (java.io.PushbackReader. r)] + (edn/read {:readers {'hottub/queue deserialize-queue}} pbr))) \ No newline at end of file