Linx.MAC (Linx v0.1.0)

Copy Markdown View Source

A 48-bit MAC (link-layer) address.

Construction

iex> Linx.MAC.parse("00:11:22:33:44:55")
{:ok, ~MAC"00:11:22:33:44:55"}

The ~MAC sigil

import Linx.MAC and build MAC literals at compile time:

iex> import Linx.MAC
iex> ~MAC"02:aa:bb:cc:dd:ee"
~MAC"02:aa:bb:cc:dd:ee"

Inspect

A MAC renders as the same sigil that would build it — ~MAC"02:aa:bb:cc:dd:ee" — so iex output round-trips into source.

Wire codec

encode/1 and decode/1 are the Linx.Netlink.Codec entry points: a Linx.MAC serializes to its 6 raw bytes; decode reads 6 bytes back.

Summary

Functions

Parses a colon-separated hex string into an Linx.MAC.

The ~MAC sigil: builds a Linx.MAC at compile time. Invalid input raises ArgumentError.

Renders a Linx.MAC as a colon-separated hex string.

Types

t()

@type t() :: %Linx.MAC{bytes: <<_::48>>}

Functions

parse(string)

@spec parse(binary()) :: {:ok, t()} | {:error, term()}

Parses a colon-separated hex string into an Linx.MAC.

sigil_MAC(arg, modifiers)

(macro)

The ~MAC sigil: builds a Linx.MAC at compile time. Invalid input raises ArgumentError.

to_string(mac)

@spec to_string(t()) :: binary()

Renders a Linx.MAC as a colon-separated hex string.