3 ms·
> There is no good reason to use big-endian serialization For this particular use case of variable length integers, I think there are very good reasons. Easie
by Const-me 2y ago
> There is no good reason to use big-endian serialization
For this particular use case of variable length integers, I think there are very good reasons.
Easier to debug because the encoding doesn’t change bytes. You encode 0x01FF45 and you will get 21 FF 45 bytes which is very human readable. Little endian will get you 2C FA 0F bytes which is completely unrecognizable in debugger, or in files on disk.
Simpler to implement. If you encode a full uint64_t you gonna get 9 encoded bytes yet computers can’t easily handle 9 bytes integers, they only go up to 8.
The implementation is more efficient because you don’t need to bit shift input numbers. Many modern processors have BZHI instruction to zero out higher bits in an integer which is faster than BEXTR instruction to extract bits.