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
Adds numeric operands without allowing float conversion or arithmetic exceptions to escape.
Decodes rate limiter state from its fixed-width 24-byte binary format.
Decodes rate limiter state, using fallback_start_ms for malformed values.
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.
Converts an integer or float to a finite BEAM float without raising.
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
Adds numeric operands without allowing float conversion or arithmetic exceptions to escape.
Decodes rate limiter state from its fixed-width 24-byte binary format.
Decodes rate limiter state, using fallback_start_ms for malformed values.
Raft apply paths pass their stamped apply time here so corrupted or malformed state is repaired deterministically on every replica.
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.
Converts an integer or float to a finite BEAM float without raising.
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.