Skip to content

Instantly share code, notes, and snippets.

@mokevnin
Created January 24, 2025 15:42
Show Gist options
  • Save mokevnin/c4cbe11f5d5d11ab343ab12722dcf803 to your computer and use it in GitHub Desktop.
Save mokevnin/c4cbe11f5d5d11ab343ab12722dcf803 to your computer and use it in GitHub Desktop.
binary_example.ex
defmodule BinaryParser do
def parse_header(<<version::8, length::16, payload::binary>>) do
%{
version: version,
length: length,
payload: payload
}
end
end
# Example binary data: version = 1, length = 10, payload = "HelloWorld"
binary_data = <<1, 0, 10, "HelloWorld">>
parsed_result = BinaryParser.parse_header(binary_data)
IO.inspect(parsed_result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment