Created
January 24, 2025 15:42
-
-
Save mokevnin/c4cbe11f5d5d11ab343ab12722dcf803 to your computer and use it in GitHub Desktop.
binary_example.ex
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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