quic_h3_capsule (quic v2.0.2)

View Source

Summary

Functions

Decode a single capsule from the head of a binary.

Encode a capsule as an iolist.

Types

capsule_type/0

-type capsule_type() :: non_neg_integer().

capsule_value/0

-type capsule_value() :: binary().

Functions

decode(Bin)

-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, _}.

encode(Type, Value)

-spec encode(capsule_type(), iodata()) -> iodata().

Encode a capsule as an iolist.