BitwiseIp.encode

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

Specs

encode(:inet.ip4_address()) :: v4()
encode(:inet.ip6_address()) :: v6()

Encodes an :inet-style tuple as a bitwise IP.

The Erlang standard library represents IP addresses as tuples of integers: 4 octet values for IPv4, 8 hextet values for IPv6. This function encodes the separate values as a single number, which gets wrapped into a BitwiseIp struct. This can be undone with decode/1.

Beware of redundant usage in performance-critical paths. Because of the overhead in encoding the integer, excessive translation back & forth between the formats may outweigh any benefits gained from other operations on the single-integer representation.

Examples

iex> BitwiseIp.encode({127, 0, 0, 1})
%BitwiseIp{proto: :v4, addr: 2130706433}

iex> BitwiseIp.encode({0, 0, 0, 0, 0, 0, 0, 1})
%BitwiseIp{proto: :v6, addr: 1}