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

Function EncodeSnappyBest

s2/encode.go:292–320  ·  view source on GitHub ↗

EncodeSnappyBest 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

(dst, src []byte)

Source from the content-addressed store, hash-verified

290// If you need to encode larger amounts of data, consider using
291// the streaming interface which gives all of these features.
292func EncodeSnappyBest(dst, src []byte) []byte {
293 if n := MaxEncodedLen(len(src)); n < 0 {
294 panic(ErrTooLarge)
295 } else if cap(dst) < n {
296 dst = make([]byte, n)
297 } else {
298 dst = dst[:n]
299 }
300
301 // The block starts with the varint-encoded length of the decompressed bytes.
302 d := binary.PutUvarint(dst, uint64(len(src)))
303
304 if len(src) == 0 {
305 return dst[:d]
306 }
307 if len(src) < minNonLiteralBlockSize {
308 d += emitLiteral(dst[d:], src)
309 return dst[:d]
310 }
311
312 n := encodeBlockBestSnappy(dst[d:], src)
313 if n > 0 {
314 d += n
315 return dst[:d]
316 }
317 // Not compressible
318 d += emitLiteral(dst[d:], src)
319 return dst[:d]
320}
321
322// ConcatBlocks will concatenate the supplied blocks and append them to the supplied destination.
323// If the destination is nil or too small, a new will be allocated.

Callers 5

mainFunction · 0.92
FuzzEncodingBlocksFunction · 0.85
testSnappyBlockRoundtripFunction · 0.85
benchEncodeFunction · 0.85
benchFileSnappyFunction · 0.85

Calls 3

encodeBlockBestSnappyFunction · 0.85
MaxEncodedLenFunction · 0.70
emitLiteralFunction · 0.70

Tested by 4

FuzzEncodingBlocksFunction · 0.68
testSnappyBlockRoundtripFunction · 0.68
benchEncodeFunction · 0.68
benchFileSnappyFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…