2019-05-22 23:16:55 +02:00
|
|
|
package encoding
|
|
|
|
|
|
|
|
import (
|
2019-05-24 11:34:32 +02:00
|
|
|
"github.com/VictoriaMetrics/metrics"
|
2019-05-22 23:16:55 +02:00
|
|
|
"github.com/valyala/gozstd"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CompressZSTDLevel appends compressed src to dst and returns
|
|
|
|
// the appended dst.
|
|
|
|
//
|
|
|
|
// The given compressLevel is used for the compression.
|
|
|
|
func CompressZSTDLevel(dst, src []byte, compressLevel int) []byte {
|
2019-05-24 11:34:32 +02:00
|
|
|
originalBytes.Add(len(src))
|
|
|
|
dstLen := len(dst)
|
|
|
|
dst = gozstd.CompressLevel(dst, src, compressLevel)
|
|
|
|
compressedBytes.Add(len(dst) - dstLen)
|
|
|
|
return dst
|
2019-05-22 23:16:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// DecompressZSTD decompresses src, appends the result to dst and returns
|
|
|
|
// the appended dst.
|
|
|
|
func DecompressZSTD(dst, src []byte) ([]byte, error) {
|
|
|
|
return gozstd.Decompress(dst, src)
|
|
|
|
}
|
2019-05-24 11:34:32 +02:00
|
|
|
|
|
|
|
var (
|
|
|
|
originalBytes = metrics.NewCounter(`vm_zstd_block_original_bytes_total`)
|
|
|
|
compressedBytes = metrics.NewCounter(`vm_zstd_block_compressed_bytes_total`)
|
|
|
|
)
|