Skip to main content

Module num

Module num 

Source
Expand description

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 i64 or u64, sign included.
DOUBLE_MAX
Room for the longest thing write_double or write_g17 can write.

Functions§

i64_digits
The decimal digits of n, written into the back of buf.
i64_len
The number of bytes push_i64 would append.
parse_f64
Redis’s getLongDoubleFromObject, as far as the difference is observable.
parse_i64
Parses a signed decimal integer the way Redis’s string2ll does.
push_double
Appends a double the way Redis 8 writes one.
push_g17
The same digits write_g17 would write, appended.
push_human
Appends a double the way INCRBYFLOAT and HINCRBYFLOAT write 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 of buf.
u64_len
How many digits n has.
write_double
Writes a double into a fixed buffer, byte for byte what push_double would append.
write_g17
Writes a double the way C’s %.17g writes one, which is what AROP replies with.