I am currently trying to understand how binary-size(number) works in Elixir.
In the example from The Little Elixir & OTP Guidebook there is a section where they break apart a 128 byte ID3 tag. The tag has the following properties:
- 3 byte header
- 30 byte title tag
- 30 byte artist tag
- 30 byte album tag
- 4 byte year tag
- Rest is packing
The way in which they extract this in the book is
<< "TAG", title :: binary-size(30), artist :: binary-size(30), album :: binary-size(30), year:: binary-size(4), _ :: binary >>
I am having trouble understanding how each value gets the correct value from binary-size(#num). Maybe it is the order in which the pattern matching is taking place and I am having trouble understand that. Currently I am approaching it as we first pattern match the header which is three bytes since it is hardcoded as "TAG", at this point I'm not sure how we can get the value of 30 bytes from binary-size(30). Is this operation being split up into two separate parts? Are we saying that first from 128, total byte size, we subtract 30 and then assign the value of size(30) to the title, and then carry this updated size to each value in the binary pattern match propagating any changes along the way?