From 07e542dc52cf112a7e4e5c9b81c5e52a6534b1b2 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Sat, 7 Jul 2012 19:08:42 +0700 Subject: [PATCH 1/3] Housekeeping. --- README.md | 4 ++-- src/taoensso/nippy.clj | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index df21094..9453682 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ As an example of what Nippy can do, let's take a look at its own reference stres ```clojure nippy/stress-data => -{:bytes (byte-array [(byte 1) (byte 2) (byte 3)]) +{:bytes (byte-array [(byte 1) (byte 2) (byte 3)]) :nil nil :boolean true @@ -99,7 +99,7 @@ Deserialize it: ```clojure (nippy/thaw-from-bytes frozen-stress-data) -=> {:bytes (byte-array [(byte 1) (byte 2) (byte 3)]) +=> {:bytes (byte-array [(byte 1) (byte 2) (byte 3)]) :nil nil :boolean true <...> } diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index d3e85ae..2247804 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -87,7 +87,7 @@ ~@body))) (defmacro coll-freezer - "Helper to freeze simple collection types." + "Helper to extend Freezable protocol to simple collection types." [type id & body] `(freezer ~type ~id @@ -243,7 +243,7 @@ (def stress-data "Reference data used for tests & benchmarks." {;; Breaks reader, roundtrip equality - :bytes (byte-array [(byte 1) (byte 2) (byte 3)]) + :bytes (byte-array [(byte 1) (byte 2) (byte 3)]) :nil nil :boolean true From 8f9bce289b51f7e5fa68d20e7f0ce547b9d693a3 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Sun, 8 Jul 2012 12:49:22 +0700 Subject: [PATCH 2/3] Add notes about tagged literals. --- README.md | 9 +++++++-- src/taoensso/nippy.clj | 7 ++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9453682..43eb0e2 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Nippy is an attempt to provide a drop-in, high-performance alternative to the re ## What's In The Box? * Simple, **high-performance** all-Clojure de/serializer. * Comprehesive, extensible **support for all major data types**. - * **Reader-fallback** for difficult/future types. + * **Reader-fallback** for difficult/future types (including Clojure 1.4+ tagged literals). * **Full test coverage** for every supported type. * [Snappy](http://code.google.com/p/snappy/) **integrated de/compression** for efficient storage and network transfer. @@ -85,7 +85,12 @@ nippy/stress-data :double (double 3.14) :bigdec (bigdec 3.1415926535897932384626433832795) - :ratio 22/7} + :ratio 22/7 + + ;; Clojure 1.4+ + ;; :tagged-uuid (java.util.UUID/randomUUID) + ;; :tagged-date (java.util.Date.) + } ``` Serialize it: diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index 2247804..66f05c3 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -280,4 +280,9 @@ :double (double 3.14) :bigdec (bigdec 3.1415926535897932384626433832795) - :ratio 22/7}) \ No newline at end of file + :ratio 22/7 + + ;; Clojure 1.4+ + ;; :tagged-uuid (java.util.UUID/randomUUID) + ;; :tagged-date (java.util.Date.) + }) \ No newline at end of file From cddd2eef130b3cf3e21d461a569b82dc3e77c1e3 Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Sun, 8 Jul 2012 13:00:34 +0700 Subject: [PATCH 3/3] Added support for namespaced keywords. --- README.md | 1 + src/taoensso/nippy.clj | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43eb0e2..63049ea 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,7 @@ nippy/stress-data :string-utf8 "ಬಾ ಇಲ್ಲಿ ಸಂಭವಿಸ" :string-long (apply str (range 1000)) :keyword :keyword + :ns-keyword ::keyword :list (list 1 2 3 4 5 (list 6 7 8 (list 9 10))) :list-quoted '(1 2 3 4 5 (6 7 8 (9 10))) diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index 66f05c3..14a3745 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -100,7 +100,9 @@ (freezer Character id-char (.writeChar s (int x))) (freezer String id-string (.writeUTF s x)) -(freezer Keyword id-keyword (.writeUTF s (name x))) +(freezer Keyword id-keyword (.writeUTF s (if-let [ns (namespace x)] + (str ns "/" (name x)) + (name x)))) (declare freeze-to-stream!*) @@ -252,6 +254,7 @@ :string-utf8 "ಬಾ ಇಲ್ಲಿ ಸಂಭವಿಸ" :string-long (apply str (range 1000)) :keyword :keyword + :ns-keyword ::keyword :list (list 1 2 3 4 5 (list 6 7 8 (list 9 10))) :list-quoted '(1 2 3 4 5 (6 7 8 (9 10)))