Navigation Menu

Skip to content

Commit

Permalink
added support for clojure.lang.BigInt in je_marshal
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Pariev committed Feb 23, 2012
1 parent 04e71b2 commit 98a38e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/cupboard/bdb/je.clj
Expand Up @@ -89,7 +89,7 @@
(finally (~~close-fn ~var#))))))


(defonce *lock-modes*
(defonce ^:dynamic *lock-modes*
;; NB: :serializable is not available here, as it does not make sense outside
;; a transaction.
{:read-uncommitted LockMode/READ_UNCOMMITTED
Expand Down
17 changes: 12 additions & 5 deletions src/cupboard/bdb/je_marshal.clj
Expand Up @@ -4,7 +4,7 @@
[com.sleepycat.bind.tuple TupleBinding TupleInput TupleOutput]))


(def *clj-types* [nil
(def ^:dynamic *clj-types* [nil
java.lang.Boolean
java.lang.Character
java.lang.Byte
Expand All @@ -13,6 +13,7 @@
java.lang.Long
java.math.BigInteger
clojure.lang.Ratio
clojure.lang.BigInt
java.lang.Double
java.lang.Float
java.lang.String
Expand All @@ -29,17 +30,17 @@
:seq
:map
:set
(class (boolean-array []))
(class (byte-array []))
(class (char-array []))
(class (boolean-array []))
(class (byte-array []))
(class (char-array []))
(class (double-array []))
(class (float-array []))
(class (int-array []))
(class (long-array []))
(class (object-array []))
(class (short-array []))])

(def *clj-type-codes* (zipmap *clj-types* (range 0 (count *clj-types*))))
(def ^:dynamic *clj-type-codes* (zipmap *clj-types* (range 0 (count *clj-types*))))


(defn clj-type [data]
Expand Down Expand Up @@ -75,6 +76,9 @@
(fn [#^TupleOutput tuple-output #^clojure.lang.Ratio data]
(marshal-write tuple-output (.numerator data))
(marshal-write tuple-output (.denominator data))))
(def-marshal-write clojure.lang.BigInt
(fn [#^TupleOutput tuple-output #^clojure.lang.BigInt data]
(marshal-write tuple-output (.toBigInteger data))))
(def-marshal-write java.lang.Double .writeSortedDouble)
(def-marshal-write java.lang.Float .writeSortedFloat)
(def-marshal-write java.lang.String .writeString)
Expand Down Expand Up @@ -170,6 +174,9 @@
(fn [tuple-input] (clojure.lang.Ratio.
(unmarshal-read tuple-input)
(unmarshal-read tuple-input))))
(def-unmarshal-read clojure.lang.BigInt
(fn [tuple-input] (clojure.lang.BigInt/fromBigInteger
(unmarshal-read tuple-input))))
(def-unmarshal-read java.lang.Double .readSortedDouble)
(def-unmarshal-read java.lang.Float .readSortedFloat)
(def-unmarshal-read java.lang.String .readString)
Expand Down

0 comments on commit 98a38e8

Please sign in to comment.