Read the uncompressed length stored at the start of the compressed data. On success, stores the length in *result and returns true. On failure, returns false.
| 1611 | // On success, stores the length in *result and returns true. |
| 1612 | // On failure, returns false. |
| 1613 | bool ReadUncompressedLength(uint32_t* result) { |
| 1614 | assert(ip_ == NULL); // Must not have read anything yet |
| 1615 | // Length is encoded in 1..5 bytes |
| 1616 | *result = 0; |
| 1617 | uint32_t shift = 0; |
| 1618 | while (true) { |
| 1619 | if (shift >= 32) return false; |
| 1620 | size_t n; |
| 1621 | const char* ip = reader_->Peek(&n); |
| 1622 | if (n == 0) return false; |
| 1623 | const unsigned char c = *(reinterpret_cast<const unsigned char*>(ip)); |
| 1624 | reader_->Skip(1); |
| 1625 | uint32_t val = c & 0x7f; |
| 1626 | if (LeftShiftOverflows(static_cast<uint8_t>(val), shift)) return false; |
| 1627 | *result |= val << shift; |
| 1628 | if (c < 128) { |
| 1629 | break; |
| 1630 | } |
| 1631 | shift += 7; |
| 1632 | } |
| 1633 | return true; |
| 1634 | } |
| 1635 | |
| 1636 | // Process the next item found in the input. |
| 1637 | // Returns true if successful, false on error or end of input. |
no test coverage detected