github.com/hack0072008/kafka-go@v1.0.1/compression.go (about)

     1  package kafka
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/hack0072008/kafka-go/compress"
     7  )
     8  
     9  type Compression = compress.Compression
    10  
    11  const (
    12  	Gzip   Compression = compress.Gzip
    13  	Snappy Compression = compress.Snappy
    14  	Lz4    Compression = compress.Lz4
    15  	Zstd   Compression = compress.Zstd
    16  )
    17  
    18  type CompressionCodec = compress.Codec
    19  
    20  // TODO: this file should probably go away once the internals of the package
    21  // have moved to use the protocol package.
    22  const (
    23  	compressionCodecMask = 0x07
    24  )
    25  
    26  var (
    27  	errUnknownCodec = errors.New("the compression code is invalid or its codec has not been imported")
    28  )
    29  
    30  // resolveCodec looks up a codec by Code()
    31  func resolveCodec(code int8) (CompressionCodec, error) {
    32  	codec := compress.Compression(code).Codec()
    33  	if codec == nil {
    34  		return nil, errUnknownCodec
    35  	}
    36  	return codec, nil
    37  }