Skip to content

Commit

Permalink
packet/compression.go: Introduce NopCompression, solves #225
Browse files Browse the repository at this point in the history
  • Loading branch information
TwistedAsylumMC committed Aug 2, 2024
1 parent c32a9a2 commit 612f65f
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions minecraft/protocol/packet/compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ type Compression interface {
}

var (
// NopCompression is an empty implementation that does not compress data.
NopCompression nopCompression
// FlateCompression is the implementation of the Flate compression
// algorithm. This was used by default until v1.19.30.
FlateCompression flateCompression
Expand All @@ -32,6 +34,8 @@ var (
)

type (
// nopCompression is an empty implementation that does not compress data.
nopCompression struct{}
// flateCompression is the implementation of the Flate compression algorithm. This was used by default until v1.19.30.
flateCompression struct{}
// snappyCompression is the implementation of the Snappy compression algorithm. This is used by default.
Expand All @@ -52,6 +56,21 @@ var (
}
)

// EncodeCompression ...
func (nopCompression) EncodeCompression() uint16 {
return CompressionAlgorithmNone
}

// Compress ...
func (nopCompression) Compress(decompressed []byte) ([]byte, error) {
return decompressed, nil
}

// Decompress ...
func (nopCompression) Decompress(compressed []byte) ([]byte, error) {
return compressed, nil
}

// EncodeCompression ...
func (flateCompression) EncodeCompression() uint16 {
return CompressionAlgorithmFlate
Expand Down

0 comments on commit 612f65f

Please sign in to comment.