jayendra13 / simpleubjson

Automatically exported from code.google.com/p/simpleubjson
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

Support new type markers for objects and arrays #8

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
According to the type reference (http://ubjson.org/type-reference/) and my 
understanding of issue 16 
(https://github.com/thebuzzmedia/universal-binary-json/issues/16), "[" and "{" 
are the new type markers for arrays and objects, and "A", "a", "O" and "o" are 
all being deprecated. Can simpleubjson be made to decode both versions of the 
format?

Original issue reported on code.google.com by m...@codeforamerica.org on 13 Jul 2013 at 9:46

GoogleCodeExporter commented 8 years ago
I see now that that there is a "spec" keyword arg to the ub.decode() method. 
Can the default behavior be a permissive parser that understands both 8 and 9 
syntax when decoding?

Original comment by m...@codeforamerica.org on 13 Jul 2013 at 9:50

GoogleCodeExporter commented 8 years ago
Probably, it's time to set Draft-9 as default one. I just pushed this change in 
ref017d0e09aa and using Draft-8 is considered deprecated. I'll take a look is 
there everything is ready and make 0.7 release on head of next week. Stay 
tuned! (:

> Can the default behavior be a permissive parser that understands both 8 and 9 
syntax when decoding?

I prefer explicit way of such guessing, so in client code you'll have something 
like:

try:
  obj = simpleubjson.decode(data, spec='draft-9')
except simpleubjson.DecodeError:
  obj = simpleubjson.decode(data, spec='draft-8')

or vice versa. Having same code in simpleubjson doesn't make a sense and may 
hurt you performance since on spec upgrading data have to be parsed twice (and 
twice it may fails for malformed data). Also this trick fails for steamed, so 
you have to keep somewhere buffer to not lose already decoded data.

Original comment by kxepal on 13 Jul 2013 at 11:48

GoogleCodeExporter commented 8 years ago
The try/catch seems fair to me, thanks!

Original comment by m...@codeforamerica.org on 14 Jul 2013 at 6:57