Refactor: Remove VarInt type, replace with int32, and consolidate encoding/decoding logic

This commit is contained in:
adman
2025-12-24 00:29:43 +01:00
parent 2f81976fe8
commit dd41115ca2
10 changed files with 41 additions and 32 deletions
+6 -7
View File
@@ -53,7 +53,7 @@ func (c *Conn) Send(packet any) (err error) {
if c.CompressionThreshold > 0 {
packetBuffer := bytes.NewBuffer(nil)
if int32(len(packetBytes)) >= c.CompressionThreshold {
err = proto_base.VarInt(len(packetBytes)).Encode(packetBuffer)
err = proto_base.EncodeVarInt(packetBuffer, int32(len(packetBytes)))
if err != nil {
return
}
@@ -62,7 +62,7 @@ func (c *Conn) Send(packet any) (err error) {
return
}
} else {
err = proto_base.VarInt(0).Encode(packetBuffer)
err = proto_base.EncodeVarInt(packetBuffer, 0)
if err != nil {
return
}
@@ -75,7 +75,7 @@ func (c *Conn) Send(packet any) (err error) {
} else {
packetBytes = rawPacketBytes
}
err = proto_base.VarInt(len(packetBytes)).Encode(c.W)
err = proto_base.EncodeVarInt(c.W, int32(len(packetBytes)))
if err != nil {
return
}
@@ -84,8 +84,7 @@ func (c *Conn) Send(packet any) (err error) {
}
func (c *Conn) Receive() (packet any, err error) {
var rawPacketLen proto_base.VarInt
rawPacketLen, err = rawPacketLen.Decode(c.R)
rawPacketLen, err := proto_base.DecodeVarInt(c.R)
if err != nil {
return
}
@@ -96,8 +95,8 @@ func (c *Conn) Receive() (packet any, err error) {
rawPacketBuffer := bytes.NewBuffer(rawPacketBytes)
var packetBytes []byte
if c.CompressionThreshold > 0 {
var packetLen proto_base.VarInt
packetLen, err = packetLen.Decode(rawPacketBuffer)
var packetLen int32
packetLen, err = proto_base.DecodeVarInt(rawPacketBuffer)
if err != nil {
return
}