Pfx.digits
You're seeing just the function
digits
, go back to Pfx module for more information.
Specs
digits(prefix(), pos_integer()) :: {tuple(), pos_integer()}
Returns a {{digit, ..}, length}
representation of given pfx
.
The pfx
is padded to its maximum length using 0
's and the resulting
bits are grouped into digits, each width
-bits wide. The resulting length
denotes the prefix' original bit_size.
Note: works best if the prefix' maxlen
is a multiple of the width
used,
otherwise maxlen
cannot be inferred from this format by tuple_size(digits) * width
(e.g. by Pfx.undigits/2
)
Examples
iex> digits("10.11.12.0/24", 8)
{{10, 11, 12, 0}, 24}
# mask is applied first
iex> digits("10.11.12.13/24", 8)
{{10, 11, 12, 0}, 24}
iex> digits("acdc:1976::/32", 16)
{{44252, 6518, 0, 0, 0, 0, 0, 0}, 32}
iex> digits({{0xacdc, 0x1976, 0, 0, 0, 0, 0, 0}, 32}, 16)
{{44252, 6518, 0, 0, 0, 0, 0, 0}, 32}
iex> digits(%Pfx{bits: <<10, 11, 12>>, maxlen: 32}, 8)
{{10, 11, 12, 0}, 24}
iex> digits(%Pfx{bits: <<10, 11, 12, 1::1>>, maxlen: 32}, 8)
{{10, 11, 12, 128}, 25}
iex> digits(%Pfx{bits: <<0x12, 0x34, 0x56, 0x78>>, maxlen: 128}, 4)
{{1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 32}