alavrik / piqi

Piqi – universal schema language: JSON, XML, Protocol Buffers data validation and conversion
http://piqi.org
Apache License 2.0
246 stars 36 forks source link

json/xml serialization problems with unsigned ints > 2^63 #36

Closed motiejus closed 11 years ago

motiejus commented 11 years ago

Hi,

I am playing with a number slightly more than 2^63:

> math:log(9223653511831486465) / math:log(2).
63.00004402688683

Let's try it out:

$ echo  "{\"value\":9223372036854841345}" | piqi convert -f json -t piq --type uint64-fixed
:uint64-fixed 65537

$ echo  "{\"value\":9223372036854841345}" | piqi convert -f json -t piq --type uint64
:uint64 65537

I expect it to return 9223372036854841345. Same problem the other way around (piq -> json).

With google protocol buffers it appears to work (tested from Erlang):

$ cat t1.piqi
.alias [ .name gid1 .type uint64-fixed ]
.alias [ .name gid2 .type uint64 ]
19> t_piqi:parse_gid2(t_piqi:gen_gid2(9223653511831486465, json), json).      
65537
20> t_piqi:parse_gid1(t_piqi:gen_gid1(9223653511831486465, json), json).      
1
21> t_piqi:parse_gid1(iolist_to_binary(t_piqi:gen_gid1(9223653511831486465))).
9223653511831486465
22> t_piqi:parse_gid2(iolist_to_binary(t_piqi:gen_gid2(9223653511831486465))).
9223653511831486465
alavrik commented 11 years ago

Hey Motiejus, thank you for reporting this! awkward bug... It was in generated code and I was pretty sure I got it right when I first wrote this piece. Will be making a new release soon.