Xirsys.Sockets.Accumulator.LengthPrefixed (xturn_sockets v2.2.0)
View SourceFrames packets using a fixed-size length header.
The popped packet is the body only (header is stripped). Multiple packets
in one push/3 are drained by repeated pop/1.
Options
:header_size- header width in bytes (default:2):length_offset- byte offset of the length field (default:0):length_size- width of the length field in bytes (default: header size):endianness-:bigor:little(default::big):length_includes_header- whether length counts the header (default:false):max_size- max buffered bytes before:buffer_overflow(default:65536)
Summary
Functions
Builds an empty byte buffer with the given header layout.
Extracts one body when a complete header+payload is buffered.
Appends chunk to the buffer and merges meta.
Functions
Builds an empty byte buffer with the given header layout.
Parameters
opts- see module optionsiex> alias Xirsys.Sockets.Accumulator.LengthPrefixed iex> acc = LengthPrefixed.init(header_size: 2) iex> acc = LengthPrefixed.push(acc, <<0, 3, "ABC">>, %{}) iex> {:ok, "ABC", %{}, acc} = LengthPrefixed.pop(acc) iex> elem(LengthPrefixed.pop(acc), 0) :more
Extracts one body when a complete header+payload is buffered.
Parameters
acc- state afterpush/3
Appends chunk to the buffer and merges meta.
Parameters
acc- state frominit/1chunk- more bytes (may be a partial header or several packets)meta- merged into the next successfully popped packet