Helper routine: decode the next block entry starting at "p", storing the number of shared key bytes, non_shared key bytes, and the length of the value in "*shared", "*non_shared", and "*value_length", respectively. Will not dereference past "limit". If any errors are detected, returns nullptr. Otherwise, returns a pointer to the key delta (just past the three decoded values).
| 53 | // If any errors are detected, returns nullptr. Otherwise, returns a |
| 54 | // pointer to the key delta (just past the three decoded values). |
| 55 | static inline const char* DecodeEntry(const char* p, const char* limit, |
| 56 | uint32_t* shared, uint32_t* non_shared, |
| 57 | uint32_t* value_length) { |
| 58 | if (limit - p < 3) return nullptr; |
| 59 | *shared = reinterpret_cast<const uint8_t*>(p)[0]; |
| 60 | *non_shared = reinterpret_cast<const uint8_t*>(p)[1]; |
| 61 | *value_length = reinterpret_cast<const uint8_t*>(p)[2]; |
| 62 | if ((*shared | *non_shared | *value_length) < 128) { |
| 63 | // Fast path: all three values are encoded in one byte each |
| 64 | p += 3; |
| 65 | } else { |
| 66 | if ((p = GetVarint32Ptr(p, limit, shared)) == nullptr) return nullptr; |
| 67 | if ((p = GetVarint32Ptr(p, limit, non_shared)) == nullptr) return nullptr; |
| 68 | if ((p = GetVarint32Ptr(p, limit, value_length)) == nullptr) return nullptr; |
| 69 | } |
| 70 | |
| 71 | if (static_cast<uint32_t>(limit - p) < (*non_shared + *value_length)) { |
| 72 | return nullptr; |
| 73 | } |
| 74 | return p; |
| 75 | } |
| 76 | |
| 77 | class Block::Iter : public Iterator { |
| 78 | private: |
no test coverage detected