pub fn parse_size_in_bytes(raw: &str) -> Option<u64>Expand description
Parses a size setting into a byte count, as the Agent’s GetSizeInBytes does.
This ports parseSizeInBytes and the string path of cast.ToInt:
- Surrounding whitespace is trimmed.
- If the text is at least three bytes long and ends in
borB, a precedingk,m, org(either case) selects a multiplier of 2^10, 2^20, or 2^30 and both letters are removed. Any other preceding byte leaves a multiplier of one and removes only theb. A two-byte value such as1Bis never stripped, so it is not a number. There is noT, no bareK/M/G, and noiBspelling. - The remaining text is trimmed again, an all-zero fraction is dropped (
10.0is10), and the result is read as a Go integer literal with base 0: an optional sign, then decimal digits or a0x,0o,0b, or leading-0(octal) prefix, with_digit separators only between digits or after a prefix. The value must fit in ani64. - The count is multiplied by the multiplier and must fit in a
u64.
Returns None when the Agent’s parse fails, the value is negative, or the product overflows. The
Agent reads all of these as 0 without a diagnostic, so None keeps them apart from a
configured 0. Otherwise, returns the Agent’s byte count.