MCPcopy Create free account
hub / github.com/baidu/tera / ParseKeySlice

Function ParseKeySlice

src/io/coding.cc:12–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10namespace io {
11
12bool 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
37void PackUserKey(const std::string& key, int64_t timestamp, UserKeyType type,
38 std::string* packed_key) {

Callers 4

UnpackUserKeyFunction · 0.85
ExtractTimeKeyFunction · 0.85
ExtractShortKeyFunction · 0.85
ExtractKeyTypeFunction · 0.85

Calls 4

dataMethod · 0.80
DecodeFixed64Function · 0.70
SliceClass · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected