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

Function encodeGo

s2/encode_all.go:32–62  ·  view source on GitHub ↗
(dst, src []byte)

Source from the content-addressed store, hash-verified

30}
31
32func encodeGo(dst, src []byte) []byte {
33 if n := MaxEncodedLen(len(src)); n < 0 {
34 panic(ErrTooLarge)
35 } else if len(dst) < n {
36 dst = make([]byte, n)
37 }
38
39 // The block starts with the varint-encoded length of the decompressed bytes.
40 d := binary.PutUvarint(dst, uint64(len(src)))
41
42 if len(src) == 0 {
43 return dst[:d]
44 }
45 if len(src) < minNonLiteralBlockSize {
46 d += emitLiteral(dst[d:], src)
47 return dst[:d]
48 }
49 var n int
50 if len(src) < 64<<10 {
51 n = encodeBlockGo64K(dst[d:], src)
52 } else {
53 n = encodeBlockGo(dst[d:], src)
54 }
55 if n > 0 {
56 d += n
57 return dst[:d]
58 }
59 // Not compressible
60 d += emitLiteral(dst[d:], src)
61 return dst[:d]
62}
63
64// encodeBlockGo encodes a non-empty src to a guaranteed-large-enough dst. It
65// assumes that the varint-encoded length of the decompressed bytes has already

Callers 2

FuzzEncodingBlocksFunction · 0.85
roundtripFunction · 0.85

Calls 4

encodeBlockGo64KFunction · 0.85
encodeBlockGoFunction · 0.85
MaxEncodedLenFunction · 0.70
emitLiteralFunction · 0.70

Tested by 2

FuzzEncodingBlocksFunction · 0.68
roundtripFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…