Created
July 31, 2019 02:29
-
-
Save tony612/27d5f835ac36018fae002bbee270d98d to your computer and use it in GitHub Desktop.
Revisions
-
tony612 created this gist
Jul 31, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ 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