Quicr / numero-uri

BSD 2-Clause "Simplified" License
1 stars 0 forks source link

Encoding seem wrong #27

Closed fluffy closed 1 year ago

fluffy commented 1 year ago

If I add a template for then encode encode https://webex.com/1/meeting0/room0

I get a hex number of 56BC75E2D631000000000000000

Similarly is I move I do pen 0 and https://webex.com/0/meeting0/room1

I get a hex dec number of 0000000000000000025600000000000000000000 which is hex 56BC75E2D6310000000

I did not poke into how this is all going but something is not right in encoding or in print out of number of something

BrettRegnier commented 1 year ago

This is mostly due to this not really being a proper 'int128', its more like two int64s slapped together to expand the number range we can do. I can change this to be more akin to a proper int128 where the value correct instead of two append int64

BrettRegnier commented 1 year ago

Upon further testing, I believe this is actually correct. It kind of appears off due to how the values are split from each other. For example: encode https://webex.com/1/meeting0/room0 Decimal result -> 00000001099511627776 00000000000000000000 Hex result -> 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00

Whereas encode https://webex.com/0/meeting0/room1 Decimal result -> 00000000000000000256 00000000000000000000 Hex result -> 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00

These both are what we would expect to see when the pen is bits 24 and then meeting is int16 and room is int16. The bits get in kind of odd positioning

fluffy commented 1 year ago

So output the two int64 in decimal and concatinging string is not really a valid way do an 128 bit integer. Here is my recommendation, lets just switch to the only string representations of the 128 bit ints are are in hex ( and start with 0x to indicate that and include all ldeading zeros so they are allways the same length ascii string) and then I think this will be much easier to figure out and sounds like problem will go away.

BrettRegnier commented 1 year ago

Fixed my janky implementation of uin128 on this commit. It now actually behaves as expected.