diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj index 96bc300..9b645a9 100644 --- a/src/taoensso/nippy.clj +++ b/src/taoensso/nippy.clj @@ -1426,15 +1426,18 @@ (.writeUTF [data-output] (:data x)))" [type custom-type-id [x out] & body] (assert-custom-type-id custom-type-id) - `(extend-type ~type IFreezable1 - (~'-freeze-without-meta! [~x ~(with-meta out {:tag 'java.io.DataOutput})] - (if-not ~(keyword? custom-type-id) - ;; Unprefixed [cust byte id][payload]: - (write-id ~out ~(coerce-custom-type-id custom-type-id)) - ;; Prefixed [const byte id][cust hash id][payload]: - (do (write-id ~out ~id-prefixed-custom) - (.writeShort ~out ~(coerce-custom-type-id custom-type-id)))) - ~@body))) + (let [write-id-form + (if (keyword? custom-type-id) + ;; Prefixed [const byte id][cust hash id][payload]: + `(do (write-id ~out ~id-prefixed-custom) + (.writeShort ~out ~(coerce-custom-type-id custom-type-id))) + ;; Unprefixed [cust byte id][payload]: + `(write-id ~out ~(coerce-custom-type-id custom-type-id)))] + + `(extend-type ~type IFreezable1 + (~'-freeze-without-meta! [~x ~(with-meta out {:tag 'java.io.DataOutput})] + ~write-id-form + ~@body)))) (defmacro extend-thaw "Extends Nippy to support thawing of a custom type with given id: