On Jul 10, 2012, at 1:51 AM, Peter Taoussanis wrote:

> With the tag literal support of 1.4+, is that kind of the idiomatic way of 
> the future to structure protocols for serialized clojure data/code? 
> 
> Sorry, could you clarify what you're asking here - I'm not sure if I follow 
> what you mean by "structure protocols"? I'm not familiar with the 
> implementation details of the tagged literal support btw, so someone else 
> should probably chime in if that's the domain.


Sorry for being a little terse with my initial Q…

The idea is that you could use tagged literals for the serialized data format 
(not "protocol" as I mentioned).

In your example:

> (def my-uuid (java.util.UUID/randomUUID))
> => #uuid "c463d8d3-49f4-4e40-9937-8a9699b1af1d"
> 
> (thaw-from-bytes (freeze-to-bytes my-uuid))
> => #uuid "c463d8d3-49f4-4e40-9937-8a9699b1af1d"


You can see that the tag #uuid is taken by the reader as kind of a constructor 
that takes the string as an argument and returns/substitutes it by the uuid 
object/instance.

You could extend it such that your custom contructor function could take a 
stringified, compressed binary representation of the object. 

Alex mentions that "marshalling data to/from strings is neither fast nor small 
compared to other binary alternatives", which is true in general, but because 
those tag-contructors are yours to write, you could optimize the data format 
and encodings based on the datatype, and possibly overcome some of those 
speed/size limitations. 

The advantage is that it's all clojure and doesn't rely on java serialization, 
while the disadvantage is that it will probably always be slower/bigger than 
pure binary formats... but maybe not that much.

(disclaimer: I have no experience writing those kind of encoders/decoders - 
just interested in how they work/could-work with pros&cons)


-FrankS.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to