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

Function EncodeSnappy

s2/encode.go:204–232  ·  view source on GitHub ↗

EncodeSnappy 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 output is Snappy compatible and will likely decompress faster. The dst and src must not ove

(dst, src []byte)

Source from the content-addressed store, hash-verified

202// If you need to encode larger amounts of data, consider using
203// the streaming interface which gives all of these features.
204func EncodeSnappy(dst, src []byte) []byte {
205 if n := MaxEncodedLen(len(src)); n < 0 {
206 panic(ErrTooLarge)
207 } else if cap(dst) < n {
208 dst = make([]byte, n)
209 } else {
210 dst = dst[:n]
211 }
212
213 // The block starts with the varint-encoded length of the decompressed bytes.
214 d := binary.PutUvarint(dst, uint64(len(src)))
215
216 if len(src) == 0 {
217 return dst[:d]
218 }
219 if len(src) < minNonLiteralBlockSize {
220 d += emitLiteral(dst[d:], src)
221 return dst[:d]
222 }
223
224 n := encodeBlockSnappy(dst[d:], src)
225 if n > 0 {
226 d += n
227 return dst[:d]
228 }
229 // Not compressible
230 d += emitLiteral(dst[d:], src)
231 return dst[:d]
232}
233
234// EncodeSnappyBetter returns the encoded form of src. The returned slice may be a sub-
235// slice of dst if dst was large enough to hold the entire encoded block.

Callers 8

EncodeFunction · 0.92
FuzzEncodeFunction · 0.92
mainFunction · 0.92
FuzzEncodingBlocksFunction · 0.85
roundtripFunction · 0.85
testSnappyBlockRoundtripFunction · 0.85
benchEncodeFunction · 0.85
benchFileSnappyFunction · 0.85

Calls 3

MaxEncodedLenFunction · 0.70
emitLiteralFunction · 0.70
encodeBlockSnappyFunction · 0.70

Tested by 6

FuzzEncodeFunction · 0.74
FuzzEncodingBlocksFunction · 0.68
roundtripFunction · 0.68
testSnappyBlockRoundtripFunction · 0.68
benchEncodeFunction · 0.68
benchFileSnappyFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…