MCPcopy
hub / github.com/klauspost/compress / Encode

Function Encode

s2/encode.go:29–56  ·  view source on GitHub ↗

Encode returns the encoded form of src. The returned slice may be a sub- slice of dst if dst was large enough to hold the entire encoded block. Otherwise, a newly allocated slice will be returned. The dst and src must not overlap. It is valid to pass a nil dst. The blocks will require the same amo

(dst, src []byte)

Source from the content-addressed store, hash-verified

27// If you need to encode larger amounts of data, consider using
28// the streaming interface which gives all of these features.
29func Encode(dst, src []byte) []byte {
30 if n := MaxEncodedLen(len(src)); n < 0 {
31 panic(ErrTooLarge)
32 } else if cap(dst) < n {
33 dst = make([]byte, n)
34 } else {
35 dst = dst[:n]
36 }
37
38 // The block starts with the varint-encoded length of the decompressed bytes.
39 d := binary.PutUvarint(dst, uint64(len(src)))
40
41 if len(src) == 0 {
42 return dst[:d]
43 }
44 if len(src) < minNonLiteralBlockSize {
45 d += emitLiteral(dst[d:], src)
46 return dst[:d]
47 }
48 n := encodeBlock(dst[d:], src)
49 if n > 0 {
50 d += n
51 return dst[:d]
52 }
53 // Not compressible
54 d += emitLiteral(dst[d:], src)
55 return dst[:d]
56}
57
58var estblockPool [2]sync.Pool
59

Callers 15

ExampleMakeDict_zstdFunction · 0.92
mainFunction · 0.92
TestEncodeHugeFunction · 0.70
FuzzEncodingBlocksFunction · 0.70
FuzzDecodeBlockFunction · 0.70
roundtripFunction · 0.70
testBlockRoundtripFunction · 0.70
benchDecodeFunction · 0.70
benchEncodeFunction · 0.70
benchFileFunction · 0.70

Calls 3

MaxEncodedLenFunction · 0.70
emitLiteralFunction · 0.70
encodeBlockFunction · 0.70

Tested by 15

ExampleMakeDict_zstdFunction · 0.74
TestEncodeHugeFunction · 0.56
FuzzEncodingBlocksFunction · 0.56
FuzzDecodeBlockFunction · 0.56
roundtripFunction · 0.56
testBlockRoundtripFunction · 0.56
benchDecodeFunction · 0.56
benchEncodeFunction · 0.56
benchFileFunction · 0.56
TestEncoderRegressionFunction · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…