taoensso / nippy

The fastest serialization library for Clojure
https://www.taoensso.com/nippy
Eclipse Public License 1.0
1.04k stars 60 forks source link

String.getBytes and nippy #6

Closed alolis closed 11 years ago

alolis commented 11 years ago

Hello,

I wanted to ask if nippy is doing anything special when you freeze-to-bytes a string because I have noticed that if I do this:

(thaw-from-bytes (.getBytes "my-string"))

then it simply won't work even though I expected for strings to work fine. I am curious, what is the reason for this?

Thank you for your time

mpenet commented 11 years ago

nippy prepends a type id (an int) to the byte array, so that it knows how to decode it, it would be impossible to "guess" the type otherwise. As a result thaw-from-bytes will only work with byte arrays created using freeze-to-bytes.

https://github.com/ptaoussanis/nippy/blob/master/src/taoensso/nippy.clj#L12 https://github.com/ptaoussanis/nippy/blob/master/src/taoensso/nippy.clj#L195

alolis commented 11 years ago

I see, makes sense. Thanks for the reply mpenet :)

ptaoussanis commented 11 years ago

Thanks Max!