|
Pretty much functions with pattern matching all-across, passing around bitstrings, relatively dynamically typed. Grab a buffer, make sure it's at least as long as BHS, shove into BHS, ok, make sure it's at least as long as what the BHS requires... Pattern matching is the hidden power of Elixir that's probably the hardest to get fluent with, it's IMHO harder than Rust's equivalent (because of gradual typing!) - but when it works it blows Pythons' match syntax way, way out. # Example: Login Request with immediate = 0x03 | 0x40 = 0x43.
defp parse_lengths(<<
_reserved::1, _i_bit::1, opcode::6,
_flags::8,
_specific1::16,
ahs_length::8,
data_length::24,
_rest::binary
>>) do
{:ok, opcode, ahs_length * 4, data_length}
end
defp parse_lengths(_), do: {:error, :invalid_bhs}
|
Overall, it's really cool to see Elixir applied like this. Congrats on the launch!