-
Notifications
You must be signed in to change notification settings - Fork 799
/
Copy pathcompression.go
54 lines (45 loc) · 1.04 KB
/
compression.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package kafka
const (
CompressionNone int8 = iota
CompressionGZIP
CompressionSnappy
CompressionLZ4
)
// CompressionCodec represents a compression codec to encode and decode
// the messages.
type CompressionCodec interface {
String() string
Encode(dst, src []byte) (int, error)
Decode(dst, src []byte) (int, error)
}
const compressionCodecMask int8 = 0x03
const DefaultCompressionLevel int = -1
func init() {
RegisterCompressionCodec(0, func() CompressionCodec {
return CompressionCodecNone{}
})
}
type CompressionCodecNone struct{}
func (c CompressionCodecNone) String() string {
return "none"
}
func (c CompressionCodecNone) Encode(dst, src []byte) (int, error) {
return copy(dst, src), nil
}
func (c CompressionCodecNone) Decode(dst, src []byte) (int, error) {
return copy(dst, src), nil
}
func codecToStr(codec int8) string {
switch codec {
case CompressionNone:
return "none"
case CompressionGZIP:
return "gzip"
case CompressionSnappy:
return "snappy"
case CompressionLZ4:
return "lz4"
default:
return "unknown"
}
}