-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Expand file tree
/
Copy pathcodec.go
More file actions
32 lines (24 loc) · 820 Bytes
/
codec.go
File metadata and controls
32 lines (24 loc) · 820 Bytes
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
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package fileexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter"
import "github.com/klauspost/compress/zstd"
// compressFunc defines how to compress encoded telemetry data.
type compressFunc func(src []byte) []byte
var encoder, _ = zstd.NewWriter(nil)
var encoders = map[string]compressFunc{
compressionZSTD: zstdCompress,
}
func buildCompressor(compression string) compressFunc {
if compression == "" {
return noneCompress
}
return encoders[compression]
}
// zstdCompress compress a buffer with zstd
func zstdCompress(src []byte) []byte {
return encoder.EncodeAll(src, make([]byte, 0, len(src)))
}
// noneCompress return src
func noneCompress(src []byte) []byte {
return src
}