7VZF66GPW6DKQB4FU4PTU3CEE32MTYNP4MH6GY4SMICRERO76WDQC
def parse(enum) do
Stream.transform(
enum,
%__MODULE__{
parsers: [
magic: bytes(<<0x00, 0x61, 0x73, 0x6D>>)
],
acc: <<>>
},
fn
_, :stop ->
{:halt, :stop}
def new() do
%__MODULE__{
parsers: [
magic: bytes(<<0x00, 0x61, 0x73, 0x6D>>)
]
}
end
def parse_one(<<>>, state) do
{nil, state, <<>>}
end
case state do
%__MODULE__{parsers: []} ->
{[{:error, {:no_parsers, chunk}}], :stop}
def parse_one(chunk, state = %__MODULE__{parsers: [{tag, parser} | rest_parsers]}) do
case parser.(chunk) do
:not_matched ->
{{:error, {:not_matched, chunk, tag}}, state, chunk}
:not_matched ->
{[{:error, {:not_matched, chunk, tag}}], :stop}
end
end
end
)
case result do
{:error, _} -> {[result | results] |> Enum.reverse(), state, tail}
_ -> parse_all(tail, state, [result | results])
end