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 NULL. Otherwise, returns a pointer to the key delta (just past the three decoded values).
| 62 | // If any errors are detected, returns NULL. Otherwise, returns a |
| 63 | // pointer to the key delta (just past the three decoded values). |
| 64 | static inline const char* DecodeEntry(const char* p, const char* limit, |
| 65 | uint32* shared, uint32* non_shared, |
| 66 | uint32* value_length) { |
| 67 | if (limit - p < 3) return nullptr; |
| 68 | *shared = reinterpret_cast<const unsigned char*>(p)[0]; |
| 69 | *non_shared = reinterpret_cast<const unsigned char*>(p)[1]; |
| 70 | *value_length = reinterpret_cast<const unsigned char*>(p)[2]; |
| 71 | if ((*shared | *non_shared | *value_length) < 128) { |
| 72 | // Fast path: all three values are encoded in one byte each |
| 73 | p += 3; |
| 74 | } else { |
| 75 | if ((p = core::GetVarint32Ptr(p, limit, shared)) == nullptr) return nullptr; |
| 76 | if ((p = core::GetVarint32Ptr(p, limit, non_shared)) == nullptr) |
| 77 | return nullptr; |
| 78 | if ((p = core::GetVarint32Ptr(p, limit, value_length)) == nullptr) |
| 79 | return nullptr; |
| 80 | } |
| 81 | |
| 82 | if (static_cast<uint32>(limit - p) < (*non_shared + *value_length)) { |
| 83 | return nullptr; |
| 84 | } |
| 85 | return p; |
| 86 | } |
| 87 | |
| 88 | class Block::Iter : public Iterator { |
| 89 | private: |
no test coverage detected