diff --git a/go.mod b/go.mod index c5f0248..1b4104f 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/teeworlds-go/protocol go 1.22.3 -require github.com/teeworlds-go/huffman v1.0.0 +require github.com/teeworlds-go/huffman/v2 v2.0.0 diff --git a/go.sum b/go.sum index 3447da3..caf9254 100644 --- a/go.sum +++ b/go.sum @@ -1,2 +1,2 @@ -github.com/teeworlds-go/huffman v1.0.0 h1:XSNMNAJZb+njNrPACsxcDrrLDXTGjZZt35FqLAuHi4I= -github.com/teeworlds-go/huffman v1.0.0/go.mod h1:kjaXpL6C6xL7CM+tWPNYjdEgVZB2GumKhx7rCDdXArU= +github.com/teeworlds-go/huffman/v2 v2.0.0 h1:eWmQe6OZ7o6Qn75ErZ0UeM+fnT0Gz6XLx0dlO2AtJ4U= +github.com/teeworlds-go/huffman/v2 v2.0.0/go.mod h1:qrL61bcSz/NZ1mQyFjAOcbza7acJQj2ltwdjetLHsOY= diff --git a/protocol7/packet.go b/protocol7/packet.go index 43062a7..cfe055e 100644 --- a/protocol7/packet.go +++ b/protocol7/packet.go @@ -4,7 +4,7 @@ import ( "fmt" "slices" - "github.com/teeworlds-go/huffman" + "github.com/teeworlds-go/huffman/v2" "github.com/teeworlds-go/protocol/chunk7" "github.com/teeworlds-go/protocol/messages7" "github.com/teeworlds-go/protocol/network7" @@ -334,10 +334,7 @@ func (packet *Packet) Unpack(data []byte) (err error) { } if packet.Header.Flags.Compression { - // TODO: try avoiding repeated initialization of the huffman tree structure - // move this into the Packet struct or even further up - huff := huffman.Huffman{} - payload, err = huff.Decompress(payload) + payload, err = huffman.Decompress(payload) if err != nil { return err } @@ -373,10 +370,8 @@ func (packet *Packet) Pack(connection *Session) []byte { } if packet.Header.Flags.Compression { - // TODO: store huffman object in connection to avoid reallocating memory - huff := huffman.Huffman{} var err error - payload, err = huff.Compress(payload) + payload, err = huffman.Compress(payload) if err != nil { panic(err) }