Skip to content

Commit

Permalink
Warn about thaw-id reset at runtime rather than expansion time
Browse files Browse the repository at this point in the history
  • Loading branch information
ptaoussanis committed Jun 1, 2015
1 parent ba87aa7 commit 13f03c7
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/taoensso/nippy.clj
Expand Up @@ -768,20 +768,22 @@
(->MyType (.readUTF data-input)))"
[custom-type-id [in] & body]
(assert-custom-type-id custom-type-id)
(when (contains? *custom-readers* (coerce-custom-type-id custom-type-id))
(println (format "Warning: resetting Nippy thaw for custom type with id: %s"
custom-type-id)))
`(swap-custom-readers!
(fn [m#]
(assoc m#
~(coerce-custom-type-id custom-type-id)
(fn [~(with-meta in {:tag 'java.io.DataInput})]
~@body)))))

(comment (defrecord MyType [data])
(extend-freeze MyType 1 [x out] (.writeUTF out (:data x)))
(extend-thaw 1 [in] (->MyType (.readUTF in)))
(thaw (freeze (->MyType "Joe"))))
`(do
(when (contains? *custom-readers* ~(coerce-custom-type-id custom-type-id))
(println (format "Warning: resetting Nippy thaw for custom type with id: %s"
~custom-type-id)))
(swap-custom-readers!
(fn [m#]
(assoc m#
~(coerce-custom-type-id custom-type-id)
(fn [~(with-meta in {:tag 'java.io.DataInput})]
~@body))))))

(comment
(defrecord MyType [data])
(extend-freeze MyType 1 [x out] (.writeUTF out (:data x)))
(extend-thaw 1 [in] (->MyType (.readUTF in)))
(thaw (freeze (->MyType "Joe"))))

;;; Some useful custom types - EXPERIMENTAL

Expand Down

0 comments on commit 13f03c7

Please sign in to comment.