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

Function MaxEncodedLen

s2/encode.go:389–418  ·  view source on GitHub ↗

MaxEncodedLen returns the maximum length of a snappy block, given its uncompressed length. It will return a negative value if srcLen is too large to encode. 32 bit platforms will have lower thresholds for rejecting big content.

(srcLen int)

Source from the content-addressed store, hash-verified

387// It will return a negative value if srcLen is too large to encode.
388// 32 bit platforms will have lower thresholds for rejecting big content.
389func MaxEncodedLen(srcLen int) int {
390 n := uint64(srcLen)
391 if intReduction == 1 {
392 // 32 bits
393 if n > math.MaxInt32 {
394 // Also includes negative.
395 return -1
396 }
397 } else if n > 0xffffffff {
398 // 64 bits
399 // Also includes negative.
400 return -1
401 }
402 // Size of the varint encoded block size.
403 n = n + uint64((bits.Len64(n)+7)/7)
404
405 // Add maximum size of encoding block as literals.
406 n += uint64(literalExtraSize(int64(srcLen)))
407 if intReduction == 1 {
408 // 32 bits
409 if n > math.MaxInt32 {
410 return -1
411 }
412 } else if n > 0xffffffff {
413 // 64 bits
414 // Also includes negative.
415 return -1
416 }
417 return int(n)
418}

Callers 15

MaxEncodedLenFunction · 0.92
EncodeFunction · 0.92
EncodeBetterFunction · 0.92
TestEncodeHugeFunction · 0.70
FuzzEncodingBlocksFunction · 0.70
encodeGoFunction · 0.70
TestDictFunction · 0.70

Calls 1

literalExtraSizeFunction · 0.85

Tested by 15

TestEncodeHugeFunction · 0.56
FuzzEncodingBlocksFunction · 0.56
TestDictFunction · 0.56
TestDictBetterFunction · 0.56
TestDictBestFunction · 0.56
TestDictBetter2Function · 0.56
TestDictBest2Function · 0.56

Used in the wild real call sites across dependent graphs

searching dependent graphs…