From 76061d4ebc0f52f8f7e469b3f12d83ea0fb4da79 Mon Sep 17 00:00:00 2001 From: layou233 Date: Sun, 8 Sep 2024 11:13:36 +0800 Subject: [PATCH] chore: Use little endian for VarInt write --- common/mcprotocol/varint.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/common/mcprotocol/varint.go b/common/mcprotocol/varint.go index 3ae168c..832a03a 100644 --- a/common/mcprotocol/varint.go +++ b/common/mcprotocol/varint.go @@ -44,24 +44,24 @@ func PutVarInt(bs []byte, n int32) (numWrite int) { bs[0] = byte(num) return 1 } else if num&0xFFFFC000 == 0 { - result := uint16((num&0x7F|0x80)<<8 | (num >> 7)) - binary.BigEndian.PutUint16(bs, result) + result := uint16((num&0x7F | 0x80) | (num>>7)<<8) + binary.LittleEndian.PutUint16(bs, result) return 2 } else if num&0xFFE00000 == 0 { bs[2] = byte(num >> 14) - startingBytes := uint16((num&0x7F|0x80)<<8 | ((num>>7)&0x7F | 0x80)) - binary.BigEndian.PutUint16(bs, startingBytes) + startingBytes := uint16((num&0x7F | 0x80) | ((num>>7)&0x7F|0x80)<<8) + binary.LittleEndian.PutUint16(bs, startingBytes) return 3 } else if num&0xF0000000 == 0 { - result := (num&0x7F|0x80)<<24 | (((num>>7)&0x7F | 0x80) << 16) | - ((num>>14)&0x7F|0x80)<<8 | (num >> 21) - binary.BigEndian.PutUint32(bs, result) + result := (num&0x7F | 0x80) | ((num>>7)&0x7F|0x80)<<8 | + ((num>>14)&0x7F|0x80)<<16 | (num>>21)<<24 + binary.LittleEndian.PutUint32(bs, result) return 4 } else { bs[4] = byte(num >> 28) - startingBytes := (num&0x7F|0x80)<<24 | ((num>>7)&0x7F|0x80)<<16 | - ((num>>14)&0x7F|0x80)<<8 | ((num>>21)&0x7F | 0x80) - binary.BigEndian.PutUint32(bs, startingBytes) + startingBytes := (num&0x7F | 0x80) | ((num>>7)&0x7F|0x80)<<8 | + ((num>>14)&0x7F|0x80)<<16 | ((num>>21)&0x7F|0x80)<<24 + binary.LittleEndian.PutUint32(bs, startingBytes) return 5 } }