> Is there a way to do binary serialization of Clojure/Java values?
> ASCII (read) and (write) are nice, but they are wasting space,
> truncating floats and are probably slow compared to binary
> serialization.
The following utility functions have worked in many cases for me:
(defn object->file [obj file]
(with-open [outp (java.io.ObjectOutputStream.
(java.io.FileOutputStream. file))]
(.writeObject outp obj)))
(defn file->object [file]
(with-open [inp (java.io.ObjectInputStream. (java.io.FileInputStream. file))]
(.readObject inp)))
(defn freeze
([obj]
(with-open [baos (java.io.ByteArrayOutputStream. 1024)
oos (java.io.ObjectOutputStream. baos)]
(.writeObject oos obj)
(.toByteArray baos)))
([obj & objs]
(freeze (vec (cons obj objs)))))
One caveat though is that currently some of the clojure data types
(like Symbols) that I thought would have been serializable are not. I
think that in the case of Clojure symbols it is being addressed
though.
Hope this helps,
Regards,
Kyle Burton
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---