August 2025
Intermediate to advanced
272 pages
6h 14m
English
It’s almost always a good idea to keep the protocol code separate from the networking code when possible. Protocol code is often stateless and free of side effects, which makes it a good candidate for isolation and easy unit testing. We’ll do this by keeping the protocol code inside a separate module, Chat.Protocol. Our protocol code will provide two functions:
decode_message/1 will take a binary and decode it into a message struct according to our chat protocol
encode_message/1 will take a message struct and encode it into a binary
Let’s set up a project before diving in. Hop into a shell and run the following command:
| | > mix new chat --sup |
| | * creating README.md |
| | * creating .formatter.exs ... |
Read now
Unlock full access