quic_h3_capsule (quic v2.0.2)
View SourceSummary
Types
-type capsule_type() :: non_neg_integer().
-type capsule_value() :: binary().
Functions
-spec decode(binary()) -> {ok, {capsule_type(), capsule_value(), binary()}} | {more, non_neg_integer()} | {error, term()}.
Decode a single capsule from the head of a binary.
Returns {ok, {Type, Value, Rest}} when a complete capsule is available, or {more, Needed} when more bytes are needed. Needed is exact only when the value itself is short: it is 1 whenever the type or length varint is still incomplete, so treat it as a hint and keep feeding bytes rather than waiting for exactly that many.
A peer can announce a length of up to 2^62-1, which yields {more, Huge} rather than an error, so bound the buffer yourself.
{error, malformed_varint} is defensive. Both empty-binary cases are intercepted first, so for any binary input decode/1 returns only {ok, _} or {more, _}.
-spec encode(capsule_type(), iodata()) -> iodata().
Encode a capsule as an iolist.