Expand description
Redis’s own integer and double text, shared with the string type.
This module lives in yo-common because the codec is not the only thing
that needs it: whether a string is stored int encoded is decided by the same
string2ll rules that decide whether a bulk length parses. Re-exported here
so that yo_resp::num keeps meaning what it meant.
Numbers to text and back, written by hand.
Every reply that carries a length or an integer goes through here, which is
every reply, so this is as hot as anything in the codec. The formatting
machinery in core::fmt would produce the same bytes and would be several
times slower for the two or three digits a bulk header usually needs, so it
is not used for integers.
Parsing is deliberately strict and matches Redis’s string2ll byte for
byte, including its refusal of leading zeros and of a leading +. The
protocol’s own lengths are parsed with it, so a stricter or looser reading
here is a real difference in what the two servers accept.
Constants§
- DIGITS_
MAX - A buffer big enough for the digits of any
i64oru64, sign included. - DOUBLE_
MAX - Room for the longest thing
write_doubleorwrite_g17can write.
Functions§
- i64_
digits - The decimal digits of
n, written into the back ofbuf. - i64_len
- The number of bytes
push_i64would append. - parse_
f64 - Redis’s
getLongDoubleFromObject, as far as the difference is observable. - parse_
i64 - Parses a signed decimal integer the way Redis’s
string2lldoes. - push_
double - Appends a double the way Redis 8 writes one.
- push_
fixed4 - Appends a distance the way the geo commands write one, which is four digits after the point and no exponent ever.
- push_
g17 - The same digits
write_g17would write, appended. - push_
human - Appends a double the way
INCRBYFLOATandHINCRBYFLOATwrite one, which is not the way everything else does. - push_
i64 - Appends the decimal digits of
n, with a minus sign if it needs one. - push_
u64 - Appends the decimal digits of
n. - u64_
digits - The decimal digits of
n, written into the back ofbuf. - u64_len
- How many digits
nhas. - write_
double - Writes a double into a fixed buffer, byte for byte what
push_doublewould append. - write_
g17 - Writes a double the way C’s
%.17gwrites one, which is whatAROPreplies with.