[erlang-questions] Binary matching partials

Vlad Dumitrescu vladdu55@REDACTED
Wed Feb 12 10:59:51 CET 2014


Hi!

I think that if your parameter is a binary, then whan you match
something that isn't combining to an integer amount of bytes you have
to add a bitstring tail.

2> <<A:6>> = <<8>>.
** exception error: no match of right hand side value <<"\b">>
3> <<A:6,_/binary>> = <<8>>.
** exception error: no match of right hand side value <<"\b">>
4> <<A:6,_/bitstring>> = <<8>>.
<<"\b">>

regards,
Vlad


On Wed, Feb 12, 2014 at 10:48 AM, Mike Oxford <moxford@REDACTED> wrote:
> decode(Charset, <<A:6,B:6,C:6,D:6, T/binary>>, Acc)
>
> Match incoming stuff, 3 bytes at a time and put the remainder in T.  No
> problem.
>
> If I get 5 bytes it has issues because it's not on the 3-byte boundary.
> Fine ... except ...
>
> I've tried...
>
> 1)  Match less params...try <<A,B,C,D, T>> then <<A,B,C,D >>, <<A,B,C>>,
> <<A,B>> and so on.
> 2)  Match against zeros <<A:6, B:6, 0:6, 0:6>>
> 3)  Match against various combinations of bit-widths and remainder/tails
>
> It seems as if it must match exactly, yet matching against the varying
> levels of parameters doesn't seem to work.
>
> I couldn't find anything on Google about this particular matching case.
>
> Thanks in advance!
>
>
>
>
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list