Re: starter trying to figure out a binary pattern match
Felipe Vieira <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CAMZ6u3v_5XfhXpdzxYHM0RiicLW5+06tY9aDWVdjg8bav++f5g@mail.gmail.com> |
Thanks for all of the answers (cheatsheet + pointers to resources). For completeness the best I could come up with is: ``` -define(ID3V1_HEADER, "TAG"). ⋯ is_id3v1(<<?ID3V1_HEADER, Tag:(128 - byte_size(<<?ID3V1_HEADER>>))/binary>>) -> ⋯ ``` Markus Greim <[email protected]> در تاریخ پنجشنبه ۲۱ اکتبر ۲۰۲۱ ساعت ۷:۰۰ نوشت: > Hi Magnus, > > congratulations! this "cheat sheet" is fantastic, best explanation of > Erlang binaries ever seen! > > <<"Grüße"/utf8>> > > Markus > [image: Sent from Front] > > On October 21, 2021, 11:01 AM GMT+2 [email protected] wrote: > > I made a cheat sheet for binaries that you may find useful: > https://cheatography.com/fylke/cheat-sheets/erlang-binaries/ > > Improvement suggestions welcome! > > Regards, > Magnus > > On Thu, Oct 21, 2021 at 9:21 AM Nalin Ranjan <[email protected]> > wrote: > >> If you prefer chatting, there is a link to get a slack >> <https://erlef.org/slack-invite/erlanger> invitation under the community >> <https://www.erlang.org/community> section of erlang.org. >> >> Thanks and Regards >> Nalin Ranjan >> >> On Thu, Oct 21, 2021 at 9:37 AM Felipe Vieira <[email protected]> wrote: >> >>> Hey folks, I have just started learning Erlang and I'm loving it. >>> >>> I'm going through Armstrong's "Programming Erlang" and I'm trying to >>> build on "Reading MP3 Metadata". >>> >>> He patter matches with: >>> >>> ``` >>> parse_v1_tag(<<$T,$A,$G, Title:30/binary, Artist:30/binary, ⋯ >>> ``` >>> >>> I tried the following (and variations): >>> >>> 1. >>> >>> ``` >>> -define(ID3V2_HEADER, "TAG"). >>> ⋯ >>> is_id3v2(<<?ID3V2_HEADER, Tag:(128 - byte_size(?ID3V2_HEADER))/binary>>) >>> -> >>> ``` >>> >>> 2. >>> >>> ``` >>> -define(ID3V2_HEADER, <<"TAG":3/binary>>). >>> ⋯ >>> is_id3v2(<<?ID3V2_HEADER, Tag:(128 - byte_size(?ID3V2_HEADER))/binary>>) >>> -> >>> ``` >>> >>> And I'm trying to achieve a match like this (which also does not work, >>> but states more clearly my intentions): >>> >>> ``` >>> <<"TAG">> ++ <<X>> = <<84,65,71,73,86,46,32,87,46>>. >>> ``` >>> >>> Is there a way to achieve this together with the `128 - >>> byte_size(?ID3V2_HEADER))/binary>>` calculation? >>> >>> Best, >>> >>> PS: is there a more informal/chat-like place to ask these kinds of >>> questions? >>> >>