Parse a binary protocol with Erlang bit syntax
8 steps · about 1 h 58 min · Intermediate
- Learn segment sizes, types and endianness (reference, Erlang/OTP documentation, 25 min)
The full guide to constructing and matching binaries.
- Work through the bit syntax section with RGB and TCP examples (tutorial, Learn You Some Erlang, 25 min)
Friendly worked examples of pulling headers out of packets.
- Know big-endian versus little-endian byte order (article, Wikipedia, 10 min)
Explains why the same bytes mean different numbers on the wire.
- Design a type-length-value packet (article, Wikipedia, 8 min)
A simple framing format you can decode in one match.
- Use binary patterns in function heads (reference, Erlang/OTP documentation, 10 min)
Shows how binary segments fit into ordinary pattern matching.
- Split and search binaries with the binary module (reference, Erlang/OTP documentation, 10 min)
Covers split, match and part when a pattern alone is not enough.
- Build and match binaries efficiently (reference, Erlang/OTP documentation, 15 min)
Explains sub-binaries and appending so parsers stay fast.
- Let gen_tcp frame length-prefixed packets (reference, Erlang/OTP documentation, 15 min)
The {packet, N} option hands you whole messages to decode.