Decode a trail of <<Header, Length, Payload, ......, Header, Length, Payload,.......>> from Binary Input
Jesper Louis Andersen
jesper.louis.andersen@REDACTED
Tue Jul 14 23:59:53 CEST 2020
- Previous message (by thread): Decode a trail of <<Header, Length, Payload, ......, Header, Length, Payload,.......>> from Binary Input
- Next message (by thread): Decode a trail of <<Header, Length, Payload, ......, Header, Length, Payload,.......>> from Binary Input
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
On Tue, Jul 14, 2020 at 11:44 PM Papa Tana <papa.tana101@REDACTED> wrote:
> << _:8, Length1:8, Rest1/binary >>
> = Data,
> NumberOfOctets1 = Length1*8,
>
> << _:8, _:8,
> Content1:NumberOfOctets1, Rest11/binary>> = Rest1,
> {ok,
> <<Header:8,Length1:8,Content1:NumberOfOctets1>>, Rest11};
>
There are two problems here you are running into:
First, you split Data into a header, a length and the rest. But then you
split Rest1 again, skipping the header and length. So you are skipping
twice over the header and the length. You need to remove `_:8, _:8` because
you already stripped that off when you hand in Rest1.
The other problem is that when you write `Content1:NumberOfOctets1` Erlang
defaults that to an integer, but you probably want a binary (and they
default to a multiple of 8 octet size, so you could write
`Content1:Length1/binary`.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20200714/5e78be61/attachment.htm>
- Previous message (by thread): Decode a trail of <<Header, Length, Payload, ......, Header, Length, Payload,.......>> from Binary Input
- Next message (by thread): Decode a trail of <<Header, Length, Payload, ......, Header, Length, Payload,.......>> from Binary Input
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the erlang-questions
mailing list