tailrecursion / cljson

Clojure/ClojureScript library for accelerated browser data deserialization
62 stars 4 forks source link

Better encoding of records #5

Open si14 opened 10 years ago

si14 commented 10 years ago

It seems reasonable to me to skip field names while encoding records if we can share record definitions between CLJ and CLJS, so (map->Person {:a 1 :b 2}) will become ["user.Person" 1 2]. This way we can save some space in the wire. If you are interested, I can try to come up with PR eventually, what do you think?

micha commented 10 years ago

That sounds good to me. Totally makes sense, provided it doesn't break too many things...

  1. If there is no record definition on one side (i.e. the shared record definition assumption is false) then you'll get an exception with the current algorithm anyway, right? So your proposal won't break anything or require new restrictions on user code?
  2. Does this mean you'd need to use something other than the standard clojure data reader functions to decode records? How do you know how the fields are ordered? Maybe cljson-encode and cljson-decode multimethods instead, that you would extend on both sides (cljs and clj)? What if its only extended on one side?
  3. This won't affect performance when encoding/decoding regular persistent data structures like maps, vectors, etc., as this is the case we want to make sure is fast and correct?

Thanks for all your help!