def TraceState.truncate

bend-trace-context@0.2.0.0 · trace_context.bend:2487

import bend-trace-context@0.2.0.0/trace_context.bend as TraceContext
import Base

2487# Fit a state to the output budget of `limits` by removing whole entries
2488# (W3C 3.3.3.1, spec #1): while the value is over the budget, remove the
2489# rightmost entry larger than 128 octets, or the rightmost entry when none is,
2490# and stop as soon as it fits. The surviving entries keep their order (laws
2491# truncate_steps, truncate_fits, truncate_whole, truncate_order and
2492# truncate_dropped).
2493def TraceState.truncate(limits: Limits, state: TraceState) -> Truncation:
2494  +entries = TraceState.entries(state)
2495  +kept = Entries.truncate(List.length(&2, StateEntry, entries), Limits.tracestate_output(limits), entries)
2496  Truncation{TraceState.from_entries(kept, TraceState.empty()), Entries.dropped(entries, kept)}

Uses (11)

Used by (1)