Furthermore IIRC an Erlang pattern can be either matching or creation, you can't "abstract" a pattern to do both, so if you need to both parse and generate your binary thing will need to be written twice (at least).
This may or may not be an issue, but at the end of the day it's not quite equivalent to C's bitfields. It's very convenient though.
IIRC in Erlang it's something along the lines of
<<V:3/signed, F1:1, F2:1, L:3, D:L/binary, I:16/signed-little>>That Erlang syntax reminds of the python 'struct' [0], except it's generating the unpacking logic at compile time, am I right? Yes that is indeed very cool - it doesn't even seem that hard to do I'd wonder why other languages don't have a similar facility!
Kinda, however there are a few superior items to the bit syntax:
* In Erlang, the bindings are in the expression itself (whether packing or unpacking) which makes the correspondance easier.
* Because the bindings are embedded and set left to right, it becomes possible to use one binding as parameter to the next pattern e.g. `L:3, D:L/binary` will first parse 3 bits as an unsigned integer L, then extract the next L bytes as a binary substring.
* Also Erlang's bit syntax can do sub-byte matching, I don't think python's struct can.
* And Erlang's bit syntax is much clearer and orthogonal (modulo knowing the — convenient — defaults) e.g. where extracting a little-endian 32-bit signed integer with struct is "<i" with Erlang it's :32/integer-signed-little (32 units, integer, signed, little-endian; the default unit size for integers is the bit). More verbose, but also completely explicit and more flexible, and very easy to change.
[1] https://rwmj.wordpress.com/2010/02/03/on-the-awesomeness-of-...