Shared helpers for parsing, formatting, and encoding values.
Extracted from Shard and StateMachine to eliminate code duplication
(performance audit L2 / memory audit L7). Both modules delegate to this
module instead of maintaining identical private copies.
Summary
Functions
Decodes rate limiter state from a 24-byte binary or legacy string format.
Encodes rate limiter state as a fixed 24-byte binary.
Formats a float for Redis INCRBYFLOAT output: compact decimals, strips trailing zeros and unnecessary decimal point.
Parses a binary as a float. Accepts integer strings ("10") and float
strings ("3.14"). Returns {:ok, float} or :error.
Parses a binary as an integer. Returns {:ok, integer} or :error.
Functions
Decodes rate limiter state from a 24-byte binary or legacy string format.
Encodes rate limiter state as a fixed 24-byte binary.
~10x faster than the old string format ("#{cur}:#{start}:#{prev}").
No allocation, no parsing — just bit packing.
Formats a float for Redis INCRBYFLOAT output: compact decimals, strips trailing zeros and unnecessary decimal point.
Uses :binary.match/2 instead of String.contains?/2 and removes the
dead-code no-op then that was present in the original duplicated versions.
Parses a binary as a float. Accepts integer strings ("10") and float
strings ("3.14"). Returns {:ok, float} or :error.
Parses a binary as an integer. Returns {:ok, integer} or :error.