| 554 | } |
| 555 | |
| 556 | KeyValueRef decodeKV(StringRef encoded) { |
| 557 | uint8_t const* d = encoded.begin(); |
| 558 | uint64_t h, len1, len2; |
| 559 | d += sqlite3GetVarint(d, (u64*)&h); |
| 560 | d += sqlite3GetVarint(d, (u64*)&len1); |
| 561 | d += sqlite3GetVarint(d, (u64*)&len2); |
| 562 | ASSERT(d == encoded.begin() + h); |
| 563 | ASSERT(len1 >= 12 && !(len1 & 1)); |
| 564 | ASSERT(len2 >= 12 && !(len2 & 1)); |
| 565 | len1 = (len1 - 12) / 2; |
| 566 | len2 = (len2 - 12) / 2; |
| 567 | ASSERT(d + len1 + len2 == encoded.end()); |
| 568 | return KeyValueRef(KeyRef(d, len1), KeyRef(d + len1, len2)); |
| 569 | } |
| 570 | |
| 571 | // Given a key size and value prefix size, get the minimum bytes that must be read from the underlying |
| 572 | // btree tuple to safely read the prefix length from the value bytes (if the value is long enough) |