2 ms·
Actually I'm a bit disappointed that it can't format 128 bit integers or byte arrays. That would allow formatting UUIDs. I'm not a huge fan of public facing int
by andix 3y ago
Actually I'm a bit disappointed that it can't format 128 bit integers or byte arrays. That would allow formatting UUIDs. I'm not a huge fan of public facing integer IDs. There is always the risk of leaking some kind of critical information with ascending IDs.
So I will probably keep Base64URL formatting my UUIDs to make them shorter for URLs, QR Codes and so on.
Quick example:
20b30b32-d421-4cfb-bdbc-9a4e0475abea
=>
MguzICHU-0y9vJpOBHWr6g
It's important to keep in mind that there are different ways to convert an UUID to a byte array (little/big endian, order of segments, ..)
- Mogzol 3y agoEven if it could format 128 bit integers, I don't see how that would be any better than base64-encoding them. Base64 is already pretty close to the maximum efficiency you can get for shortening UUIDs while still using URL-safe characters.
- andix 3y agoTo add some of the additional features Squids provide. You can also convert any smaller integer to a string with Base64.
- stavros 3y agoThe shortuuid library can do that: https://pypi.org/project/shortuuid/ https://pypi.org/project/shortuuid/
- hippich 3y agoI actually used sqids algo for something very different where I had to encode arbitrary sized byte arrays. And with Ruby it was very simple to remove limit - I think it was matter of monkey-patching https://github.com/sqids/sqids-ruby/blob/main/lib/sqids.rb#L187 https://github.com/sqids/sqids-ruby/blob/main/lib/sqids.rb#L... to return infinity. The reason for the limit is most likely to ensure interoperability with libraries in other languages where working with bignums is much more complicated.
- andix 3y agoThis limit could easily be lifted with byte array encoding support.