MCPcopy Create free account
hub / github.com/Tencent/Tendis / getIntSize

Function getIntSize

src/tendisplus/utils/string.cpp:425–443  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

423}
424
425Expected<int64_t> getIntSize(const std::string& str) {
426 if (str.size() <= 2) {
427 return {ErrorCodes::ERR_DECODE, "getIntSize failed:" + str};
428 }
429 std::string value = str.substr(0, str.size() - 2);
430 std::string unit = str.substr(str.size() - 2, 2);
431 Expected<int64_t> size = ::tendisplus::stoll(value);
432 if (!size.ok()) {
433 return size;
434 }
435 if (unit == "kB") {
436 return size.value() * 1024;
437 } else if (unit == "mB") {
438 return size.value() * 1024 * 1024;
439 } else if (unit == "gB") {
440 return size.value() * 1024 * 1024 * 1024;
441 }
442 return {ErrorCodes::ERR_DECODE, "getIntSize failed:" + str};
443}
444
445std::string getSizeReadable(size_t size) {
446 char buf[20];

Callers 2

infoMemoryMethod · 0.85
jeprofCronMethod · 0.85

Calls 3

stollFunction · 0.85
sizeMethod · 0.80
okMethod · 0.45

Tested by

no test coverage detected