Parse size value with same format as parse_with_suffix in flow.h
| 402 | |
| 403 | // Parse size value with same format as parse_with_suffix in flow.h |
| 404 | uint64_t parseWithSuffix(const char* to_parse, const char* default_unit = nullptr) { |
| 405 | char* end_ptr = nullptr; |
| 406 | uint64_t ret = strtoull(to_parse, &end_ptr, 10); |
| 407 | if (end_ptr == to_parse) { |
| 408 | // failed to parse |
| 409 | return 0; |
| 410 | } |
| 411 | const char* unit = default_unit; |
| 412 | if (*end_ptr != 0) { |
| 413 | unit = end_ptr; |
| 414 | } |
| 415 | if (unit == nullptr) { |
| 416 | // no unit found |
| 417 | return 0; |
| 418 | } |
| 419 | if (strcmp(end_ptr, "B") == 0) { |
| 420 | // do nothing |
| 421 | } else if (strcmp(unit, "KB") == 0) { |
| 422 | ret *= static_cast<uint64_t>(1e3); |
| 423 | } else if (strcmp(unit, "KiB") == 0) { |
| 424 | ret *= 1ull << 10; |
| 425 | } else if (strcmp(unit, "MB") == 0) { |
| 426 | ret *= static_cast<uint64_t>(1e6); |
| 427 | } else if (strcmp(unit, "MiB") == 0) { |
| 428 | ret *= 1ull << 20; |
| 429 | } else if (strcmp(unit, "GB") == 0) { |
| 430 | ret *= static_cast<uint64_t>(1e9); |
| 431 | } else if (strcmp(unit, "GiB") == 0) { |
| 432 | ret *= 1ull << 30; |
| 433 | } else if (strcmp(unit, "TB") == 0) { |
| 434 | ret *= static_cast<uint64_t>(1e12); |
| 435 | } else if (strcmp(unit, "TiB") == 0) { |
| 436 | ret *= 1ull << 40; |
| 437 | } else { |
| 438 | // unrecognized unit |
| 439 | ret = 0; |
| 440 | } |
| 441 | return ret; |
| 442 | } |
| 443 | |
| 444 | struct Command { |
| 445 | private: |