如何在 Go 中将整数写入 LEB128 格式?我正在尝试将 int32 编码为我的世界 VarInt,到目前为止,我已经尝试将 wiki 上的示例导入 Go。我在测试时得到了错误的结果,维基说-1应该等于[255 255 255 255 15],但我得到的是[255 255 255 255]。我在这里做错了什么?
func WriteVarInt2(v int32) []byte{
var out []byte
c := 0
for{
currentByte := byte(v & 0b01111111)
v >>= 7
if v != 0 {
currentByte |= 0b10000000
}
out = append(out, currentByte)
c++
if c >= 5 || v == 0{
return out
}
}
}
慕田峪4524236
相关分类