Closed jviotti closed 4 years ago
OK, I ended up figuring it out by looking at the code:
-90.0715 = 1100 0010101 1010000 1001001 0011100 (0xc2b4249c)
= First 7 bits = 0011100 = 0x1c = 00011100
= Next 7 bits (>> 7) = 1001001 = 0x49 = 01001001
= Next 7 bits (>> 7) = 1010000 = 0x50 = 01010000
= Next 7 bits (>> 7) = 0010101 = 0x15 = 00010101
= Next 7 bits (>> 7) = (111)1100 = 0x7c = 01111100
29.9510 = 0100 0001111 0111110 0110111 0100110 (0x41ef9ba6)
= First 7 bits = 0100110 = 0x26 = 00100110
= Next 7 bits (>> 7) = 0110111 = 0x37 = 00110111
= Next 7 bits (>> 7) = 0111110 = 0x3e = 00111110
= Next 7 bits (>> 7) = 0001111 = 0x0f = 00001111
= Next 7 bits (>> 7) = 0100 = 0x04 = 00000100
@jviotti Apologies for a slow follow up -- I did see the issue but hadn't had time to go back read the spec+code myself.
Do you think this makes sense at this point, wrt code and wording of the spec? I think it is important that not only are things correct but also that explanation/description can be understood by developers.
@cowtowncoder No worries, I totally understand!
Do you think this makes sense at this point, wrt code and wording of the spec? I think it is important that not only are things correct but also that explanation/description can be understood by developers.
I don't think I would have been able to understand the encoding with just the spec, without looking at the code. That being said, I think that extending the spec with an example would have been more than enough (maybe one based in one of the floats I hand-encoded above?)
Example would be good idea -- do you think you could do a PR for inclusion in relevant README.md
?
@cowtowncoder I just sent https://github.com/FasterXML/smile-format-specification/pull/8. Let me know what you think!
Looks good, merged. Thank you for adding the example!
I have the following test JSON document which I'm encoding using
pysmile
.The encoded result is the following:
From the payload above, the
coord
float array is encoded like this:Based on the spec:
84
: Start of UTF-8 string of 5 characters636f 6f72 64
: String keycoord
f8
: Start of array28
: Start of 32-bit float1c49 5015 7c
: ????28
: Start of 32-bit float2637 3e0f 04
: ????f9
: End of arrayI don't understand how
1c49 5015 7c
and2637 3e0f 04
represent-90.0715
and29.9510
, respectively. The spec says:If the floats are encoded as big-endian, then the most significant bytes are
1c
and26
, respectively, which means that the 32-bit floats should be encoded as:49 5015 7c
37 3e0f 04
Which doesn't add up. Am I missing something?