| 10 | namespace io { |
| 11 | |
| 12 | bool ParseKeySlice(const leveldb::Slice& key, int64_t* timestamp, UserKeyType* type, |
| 13 | leveldb::Slice* short_key, leveldb::Slice* time_key) { |
| 14 | if (key.size() < sizeof(UserKeyType)) { |
| 15 | return false; |
| 16 | } else if (time_key) { |
| 17 | *time_key = leveldb::Slice(key.data(), key.size() - sizeof(UserKeyType)); |
| 18 | } |
| 19 | |
| 20 | if (key.size() < sizeof(uint64_t)) { |
| 21 | return false; |
| 22 | } |
| 23 | |
| 24 | if (short_key) { |
| 25 | *short_key = leveldb::Slice(key.data(), key.size() - sizeof(uint64_t)); |
| 26 | } |
| 27 | uint64_t num = DecodeFixed64(key.data() + key.size() - sizeof(uint64_t)); |
| 28 | if (type) { |
| 29 | *type = static_cast<UserKeyType>(num & 0xff); |
| 30 | } |
| 31 | if (timestamp) { |
| 32 | *timestamp = static_cast<int64_t>(num >> sizeof(UserKeyType)); |
| 33 | } |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | void PackUserKey(const std::string& key, int64_t timestamp, UserKeyType type, |
| 38 | std::string* packed_key) { |
no test coverage detected