Closed ptaoussanis closed 11 years ago
Update: an alternative would be to reserve some part of the type-id space (-128 to -1 say) for custom types, and suggest that folks extend their custom types to the current Freezable protocol.
Then thaw-from-stream
could be made extensible - perhaps with a {<custom-id> <fn-of-stream>}
map passable to thaw
/thaw-from-stream
.
As of v2.1.0 currently on the dev branch:
(defrecord MyType [data])
(nippy/extend-freeze MyType 1 ; A unique type id ∈[1, 128]
[x data-output-steam]
(.writeUTF data-output-stream (:data x)))
(nippy/extend-thaw 1 ; Same type id
[data-input-stream]
(->MyType (.readUTF data-input-stream)))
(nippy/thaw (nippy/freeze (->MyType "Joe"))) => #taoensso.nippy.MyType{:data "Joe"}
This approach makes some tradeoffs.
PROS
CONS
{:readers {Vector3D read-vector} :writers {Vector3D write-vector})
form.Any other thoughts?
Thanks to James Reeves for this suggestion:
It might result in a prefix for the data like
80 \V \e \c \t \o \r \3 \D \