I would like to do recursion over a binary, and in each call read up to 32 bits from the binary, and return it in a new binary. But I can't get the pattern matching to work as I want.
binaryToBinary(Source) ->
binaryToBinaryAux(Source, <<>>).
binaryToBinaryAux(<<>>, Target) ->
Target;
binaryToBinaryAux(<<H:32/binary, T/binary>>, Target) ->
binaryToBinaryAux(<<T/binary>>, <<Target/binary, H>>).
Here is the error I get for the pattern matching:
10> mymodule:binaryToBinary(<<"JonasPonas">>).
** exception error: no function clause matching
mymodule:binaryToBinaryAux(<<"JonasPonas">>,<<>>)
(mymodule.erl, line 51)
What am I doing wrong with the pattern matching of the binary?