I followed tutorial on http://benjamintanweihao.github.io/blog/2014/06/10/elixir-bit-syntax-and-id3/ but I could not get binary extracting at the middle working.
The author's code:
<< "TAG",
title :: [size(30), binary],
artist :: [size(30), binary],
album :: [size(30), binary],
year :: [size(4), binary],
comment :: [size(30), binary],
_rest :: binary >> = id3_tag
My code:
<< 1, x :: [size(16), binary], 4>> = << 1,2,3,4>>
Mine is not working with the following error:
** (CompileError) iex:49: unknown bitstring specifier {:size, [line: 49], [16]}, {:binary, [line: 49], nil} src/elixir_bitstring.erl:29: :elixir_bitstring.expand_bitstr/4
(elixir) src/elixir_bitstring.erl:10: :elixir_bitstring.expand/3
(elixir) src/elixir_exp_clauses.erl:10: :elixir_exp_clauses.match/3
(elixir) src/elixir_exp.erl:11: :elixir_exp.expand/2
I tried << 1, x :: size(16)-binary, 4 >> = << 1,2,3,4 >> but got ** (MatchError) no match of right hand side value: << 1, 2, 3, 4 >>.
Also, why I can do this << t, a, g >> = "TAG", but not << two, three >> = 515?
I followed tutorial on http://benjamintanweihao.github.io/blog/2014/06/10/elixir-bit-syntax-and-id3/ but I could not get binary extracting at the middle working.
The author's code:
<< "TAG",
title :: [size(30), binary],
artist :: [size(30), binary],
album :: [size(30), binary],
year :: [size(4), binary],
comment :: [size(30), binary],
_rest :: binary >> = id3_tag
My code:
<< 1, x :: [size(16), binary], 4>> = << 1,2,3,4>>
Mine is not working with the following error:
** (CompileError) iex:49: unknown bitstring specifier {:size, [line: 49], [16]}, {:binary, [line: 49], nil} src/elixir_bitstring.erl:29: :elixir_bitstring.expand_bitstr/4
(elixir) src/elixir_bitstring.erl:10: :elixir_bitstring.expand/3
(elixir) src/elixir_exp_clauses.erl:10: :elixir_exp_clauses.match/3
(elixir) src/elixir_exp.erl:11: :elixir_exp.expand/2
I tried << 1, x :: size(16)-binary, 4 >> = << 1,2,3,4 >> but got ** (MatchError) no match of right hand side value: << 1, 2, 3, 4 >>.
Also, why I can do this << t, a, g >> = "TAG", but not << two, three >> = 515?