luojia65 / mc-varint

Minecraft VarInt and VarLong implemetation in Rust, providing minimum memory usage and maximum performance.
Do What The F*ck You Want To Public License
12 stars 3 forks source link

Why does this crate use zigzag encoding? #3

Open BGR360 opened 2 years ago

BGR360 commented 2 years ago

From the protocol documentation:

Note that Minecraft's VarInts are not encoded using Protocol Buffers; it's just similar. If you try to use Protocol Buffers Varints with Minecraft's VarInts, you'll get incorrect results in some cases. The major differences:

  • Minecraft's VarInts are all signed, but do not use the ZigZag encoding. Protocol buffers have 3 types of Varints: uint32 (normal encoding, unsigned), sint32 (ZigZag encoding, signed), and int32 (normal encoding, signed). Minecraft's are the int32 variety. Because Minecraft uses the normal encoding instead of ZigZag encoding, negative values always use the maximum number of bytes.
belohnung commented 7 months ago

https://github.com/belohnung/minecraft-varint

here is my fork that fixes those issues