Skip to main content

add_delta

Function add_delta 

Source
fn add_delta(prev_key: u64, delta: u64) -> Result<VarInt, CodecError>
Expand description

Resolve a delta-encoded Type against the Type before it.

Draft-16 Section 1.4.2: “The previous Type value plus the Delta Type MUST NOT be greater than 2^64 - 1. If a Delta Type is received that would be too large, the Session MUST be closed with a PROTOCOL_VIOLATION.” Deltas accumulate, so a peer sending a handful of near-maximum deltas can drive the running sum past the end; without the checked add a debug build panics on the addition and a release build wraps and reports the pair under a Type its sender never wrote.

A resolved Type also has to be a Type this draft can express. Draft-16 writes every field as a varint, which tops out below the 2^64 - 1 the sentence names, so a sum landing above the varint maximum is refused here as well: it has no draft-16 wire form, and admitting one would produce a pair this codec could decode but never write back.