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

Method EncodeInteger

src/sdk/filter_comparator.cc:22–54  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20namespace filter {
21
22bool IntegerComparator::EncodeInteger(IntegerValueType value_type, uint64_t value,
23 std::string* encoded_value) {
24 char* buf;
25 switch (value_type) {
26 case IntegerValueType::kInt64:
27 case IntegerValueType::kUint64:
28 encoded_value->resize(sizeof(int64_t) + 1);
29 buf = const_cast<char*>(encoded_value->c_str());
30 memcpy(buf, &value, sizeof(value));
31 return true;
32 case IntegerValueType::kInt32:
33 case IntegerValueType::kUint32:
34 encoded_value->resize(sizeof(int32_t) + 1);
35 buf = const_cast<char*>(encoded_value->c_str());
36 memcpy(buf, &value, sizeof(value));
37 return true;
38 case IntegerValueType::kInt16:
39 case IntegerValueType::kUint16:
40 encoded_value->resize(sizeof(int16_t) + 1);
41 buf = const_cast<char*>(encoded_value->c_str());
42 memcpy(buf, &value, sizeof(value));
43 return true;
44 case IntegerValueType::kInt8:
45 case IntegerValueType::kUint8:
46 encoded_value->resize(sizeof(int8_t) + 1);
47 buf = const_cast<char*>(encoded_value->c_str());
48 memcpy(buf, &value, sizeof(value));
49 return true;
50 default:
51 LOG(ERROR) << "not support IntegerValueType";
52 return false;
53 }
54}
55
56bool IntegerComparator::DecodeInteger(IntegerValueType value_type, const std::string& value,
57 uint64_t* decoded_value) {

Callers 2

TEST_FFunction · 0.80
TEST_FFunction · 0.80

Calls

no outgoing calls

Tested by 2

TEST_FFunction · 0.64
TEST_FFunction · 0.64