Merge pull request #27 from weavejester/fast-date-uuid
Fast serialization for Date and UUID objects
This commit is contained in:
commit
f3b524421b
1 changed files with 12 additions and 0 deletions
|
|
@ -11,6 +11,7 @@
|
||||||
(:import [java.io DataInputStream DataOutputStream ByteArrayOutputStream
|
(:import [java.io DataInputStream DataOutputStream ByteArrayOutputStream
|
||||||
ByteArrayInputStream]
|
ByteArrayInputStream]
|
||||||
[java.lang.reflect Method]
|
[java.lang.reflect Method]
|
||||||
|
[java.util Date UUID]
|
||||||
[clojure.lang Keyword BigInt Ratio PersistentQueue PersistentTreeMap
|
[clojure.lang Keyword BigInt Ratio PersistentQueue PersistentTreeMap
|
||||||
PersistentTreeSet IPersistentList IPersistentVector IPersistentMap
|
PersistentTreeSet IPersistentList IPersistentVector IPersistentMap
|
||||||
IPersistentSet IPersistentCollection IRecord]))
|
IPersistentSet IPersistentCollection IRecord]))
|
||||||
|
|
@ -66,6 +67,9 @@
|
||||||
|
|
||||||
(def ^:const id-record (int 80))
|
(def ^:const id-record (int 80))
|
||||||
|
|
||||||
|
(def ^:const id-date (int 90))
|
||||||
|
(def ^:const id-uuid (int 91))
|
||||||
|
|
||||||
;;; DEPRECATED (old types will be supported only for thawing)
|
;;; DEPRECATED (old types will be supported only for thawing)
|
||||||
(def ^:const id-old-reader (int 1)) ; as of 0.9.2, for +64k support
|
(def ^:const id-old-reader (int 1)) ; as of 0.9.2, for +64k support
|
||||||
(def ^:const id-old-string (int 11)) ; as of 0.9.2, for +64k support
|
(def ^:const id-old-string (int 11)) ; as of 0.9.2, for +64k support
|
||||||
|
|
@ -173,6 +177,11 @@
|
||||||
(write-biginteger s (.numerator x))
|
(write-biginteger s (.numerator x))
|
||||||
(write-biginteger s (.denominator x)))
|
(write-biginteger s (.denominator x)))
|
||||||
|
|
||||||
|
(freezer Date id-date (.writeLong s (.getTime x)))
|
||||||
|
(freezer UUID id-uuid
|
||||||
|
(.writeLong s (.getMostSignificantBits x))
|
||||||
|
(.writeLong s (.getLeastSignificantBits x)))
|
||||||
|
|
||||||
(def ^:private head-meta-id (reduce-kv #(assoc %1 %3 %2) {} head-meta))
|
(def ^:private head-meta-id (reduce-kv #(assoc %1 %3 %2) {} head-meta))
|
||||||
|
|
||||||
(defn- wrap-header [data-ba metadata]
|
(defn- wrap-header [data-ba metadata]
|
||||||
|
|
@ -276,6 +285,9 @@
|
||||||
method ^Method (.getMethod class "create" meth-sig)]
|
method ^Method (.getMethod class "create" meth-sig)]
|
||||||
(.invoke method class (into-array Object [(thaw-from-stream s)])))
|
(.invoke method class (into-array Object [(thaw-from-stream s)])))
|
||||||
|
|
||||||
|
id-date (Date. (.readLong s))
|
||||||
|
id-uuid (UUID. (.readLong s) (.readLong s))
|
||||||
|
|
||||||
;;; DEPRECATED
|
;;; DEPRECATED
|
||||||
id-old-reader (edn/read-string (.readUTF s))
|
id-old-reader (edn/read-string (.readUTF s))
|
||||||
id-old-string (.readUTF s)
|
id-old-string (.readUTF s)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue