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)
| 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. |
| 389 | func 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 | } |
searching dependent graphs…