B:BD[
2.772] → [
2.772:798]
@doc """
Hello world.
def parse(enum) do
Stream.transform(
enum,
%__MODULE__{
parsers: [
magic: bytes(<<0x00, 0x61, 0x73, 0x6D>>)
],
acc: <<>>
},
fn chunk, acc ->
case acc do
%__MODULE__{parsers: []} ->
{[{:error, {:no_parsers, chunk}}], :stop}
%__MODULE__{parsers: [{tag, parser} | rest], acc: acc} = state ->
chunk = acc <> chunk
case parser.(chunk) do
:need_more ->
{[], %{state | acc: chunk}}
{:matched, data, tail} ->
{[{tag, data}], %{state | acc: tail, parsers: rest}}
:not_matched ->
{[{:error, {:not_matched, chunk, tag}}], :stop}
end