BitwiseIp.Mask.decode

You're seeing just the function decode, go back to BitwiseIp.Mask module for more information.

Specs

decode(:v4, integer()) :: 0..32
decode(:v6, integer()) :: 0..128

Decodes a bitmask into an integer prefix length.

Given the protocol (either :v4 or :v6) and a valid bitmask for that protocol, this function looks up the number of leading ones used by the bitmask. The function is only defined on valid IPv4 and IPv6 bitmasks. To undo this conversion, use encode/2.

Examples

iex> BitwiseIp.Mask.decode(:v4, 0b11111111111100000000000000000000)
12

iex> BitwiseIp.Mask.decode(:v6, 0b11111111111100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000)
12

iex> BitwiseIp.Mask.decode(:v4, 0b11111111111100000000000000000001)
** (FunctionClauseError) no function clause matching in BitwiseIp.Mask.decode/2

iex> BitwiseIp.Mask.decode(:v6, 0b0101)
** (FunctionClauseError) no function clause matching in BitwiseIp.Mask.decode/2