Replies: 1 comment 1 reply
-
Wire has been pretty successful with its implementation of a similar encoding. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm currently maintaining a library (avro4k, that is apache avro format for kotlin) and I think that okio would be really powerful as a multiplatform streaming input and output.
I would like to encode int and long using zig-zag encoding, and I would like to have a performant encoding. As there is buffer segments, reading byte by byte can be done as a slow path.
The encoding is always in little endian, and each byte has its highest bit indicating if there is another byte to read or not, that ends up to
7 bits * n bytes
(4 bytes for int and 8 bytes for long).Encoding:
Here is the int encoding (original code) , but you can guess that long encoding is similar.
Decoding:
Now the reverse, we read byte per byte (original code):
Do you think this would be the most performant, or unsafe cursors could help to improve that?
Beta Was this translation helpful? Give feedback.
All reactions