Skip to content

Instantly share code, notes, and snippets.

@tony612
Created July 31, 2019 02:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tony612/27d5f835ac36018fae002bbee270d98d to your computer and use it in GitHub Desktop.
Save tony612/27d5f835ac36018fae002bbee270d98d to your computer and use it in GitHub Desktop.
defmodule BinaryParseSlow do
def parse(bin) do
parse(bin, 0)
end
def parse(bin, acc) do
case do_parse(bin) do
{:nofin, x, rest} ->
parse(rest, acc + x)
{:fin, x} ->
acc + x
end
end
def do_parse(<<0::1, x::7, _::bits>>) do
{:fin, x}
end
def do_parse(<<1::1, x::7, rest::bits>>) do
{:nofin, x, rest}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment