Created
May 13, 2013 21:28
-
-
Save sorenmacbeth/5571680 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn write-record | |
"Write an associative data structure to Kryo's buffer. Write record | |
name as a string, count as an int, then serialize the key/value pairs." | |
[^Kryo registry ^Output output r] | |
(.writeString output (.getName (class r)) true) | |
(.writeInt output (count r) true) | |
(doseq [[k v] r] | |
(.writeClassAndObject registry output k) | |
(.writeClassAndObject registry output v))) | |
(defn read-record | |
"Read a record from Kryo's buffer. Read record name, then count, then deserialize | |
alternating key/value pairs. Transients are used for performance." | |
[^Kryo registry ^Input input] | |
(let [name (last (s/split (.readString input true) #"\."))] | |
(doall | |
(loop [remaining (.readInt input true) | |
data (transient {})] | |
(if (zero? remaining) | |
(eval `(~(symbol (str "map->" name)) ~(persistent! data))) | |
(recur (dec remaining) | |
(assoc! data | |
(.readClassAndObject registry input) | |
(.readClassAndObject registry input)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment