Y7IBP4INTUL42R7TC7O4DXGR27CKTD6VEEL6BHJNGCVIFVUVGCMQC
XMQU7NVKDFNL5MN2BECGAQI4LXQQX3GCIESGJM54GYDDLBVODLWAC
7VZF66GPW6DKQB4FU4PTU3CEE32MTYNP4MH6GY4SMICRERO76WDQC
O2DTNJ3ZOJJKDHGPNE2DZSZF7CFU4G5D65RIDOYZHYYBH3JZAAIAC
YNPPEQEWMXS4B2EKRR54WUZMXO222YOWC2I5NPXPDG2ABOIBH7RAC
UVNP57VT7S7OSGWK5XXKEBAVZMHDGGPMFGSSCT25GGSK5QFYNMFQC
magic: bytes(<<0x00, 0x61, 0x73, 0x6D>>), version: bytes(<<0x01, 0x00, 0x00, 0x00>>)
magic: bytes(<<0x00, 0x61, 0x73, 0x6D>>),
version: bytes(<<0x01, 0x00, 0x00, 0x00>>)
s(:magic, bytes(<<0x00, 0x61, 0x73, 0x6D>>)), s(:version, bytes(<<0x01, 0x00, 0x00, 0x00>>)), s(:type_section, section([bytes(<<0x01>>)]))
s(:magic, bytes(<<0x00, 0x61, 0x73, 0x6D>>)),
s(:version, bytes(<<0x01, 0x00, 0x00, 0x00>>)),
s(:type_section, section([bytes(<<0x01>>)]))
def parse_one(chunk, state = %__MODULE__{parsers: [{tag, parser} | rest_parsers]}) do
def parse_one(chunk, state = %__MODULE__{parsers: [parser | rest_parsers]}) do
{{:error, {:not_matched, chunk, tag}}, state, chunk}
{{:error, {:not_matched, chunk}}, state, chunk}
{:matched, data, tail} ->
:section_end -> new_state = %{state | parsers: rest_parsers} {:section_end, new_state, chunk} {tag, data, tail, nil} ->
:section_end ->
new_state = %{state | parsers: rest_parsers}
{:section_end, new_state, chunk}
{tag, data, tail, nil} ->
{{tag, data}, new_state, tail} {tag, data, tail, next_parser} -> new_state = %{state | parsers: [next_parser | rest_parsers]}
{{tag, data}, new_state, tail}
{tag, data, tail, next_parser} ->
new_state = %{state | parsers: [next_parser | rest_parsers]}
defp s(name, matcher) do fn chunk -> case matcher.(chunk) do {:matched, chunk, tail, next_parser} -> {name, chunk, tail, next_parser} end end end
defp s(name, matcher) do
fn chunk ->
case matcher.(chunk) do
{:matched, chunk, tail, next_parser} ->
{name, chunk, tail, next_parser}
end
{:matched, expected, rest}
{:matched, expected, rest, nil}
end end def section([]) do fn _chunk -> :section_end
def section([]) do
fn _chunk ->
:section_end
def section(parts) when is_list(parts) do fn chunk -> [parser | rest_parts] = parts case parser.(chunk) do {:matched, expected, tail, nil} -> {:matched, expected, tail, section(rest_parts)} res -> res end end end
def section(parts) when is_list(parts) do
[parser | rest_parts] = parts
case parser.(chunk) do
{:matched, expected, tail, nil} -> {:matched, expected, tail, section(rest_parts)}
res -> res