codec.go 820 B

1234567891011121314151617181920212223242526272829303132
  1. // Copyright The OpenTelemetry Authors
  2. // SPDX-License-Identifier: Apache-2.0
  3. package fileexporter // import "github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter"
  4. import "github.com/klauspost/compress/zstd"
  5. // compressFunc defines how to compress encoded telemetry data.
  6. type compressFunc func(src []byte) []byte
  7. var encoder, _ = zstd.NewWriter(nil)
  8. var encoders = map[string]compressFunc{
  9. compressionZSTD: zstdCompress,
  10. }
  11. func buildCompressor(compression string) compressFunc {
  12. if compression == "" {
  13. return noneCompress
  14. }
  15. return encoders[compression]
  16. }
  17. // zstdCompress compress a buffer with zstd
  18. func zstdCompress(src []byte) []byte {
  19. return encoder.EncodeAll(src, make([]byte, 0, len(src)))
  20. }
  21. // noneCompress return src
  22. func noneCompress(src []byte) []byte {
  23. return src
  24. }