ex_wire v0.1.1 ExWire.Struct.Endpoint
Struct to represent an endpoint in ExWire.
Link to this section Summary
Functions
Returns a struct given an ip in binary form, plus an
udp_port or tcp_port
Given an IPv4 or IPv6 address in binary form, returns the address in list form
Returns a port given a binary version of the port
as input. Note: we return nil for an empty or zero binary
Versus decode/3, and given a module with an ip, a tcp_port and
a udp_port, returns a tuple of encoded values
Given an ip address that’s an encoded as a list, returns that address encoded as a binary
Given a port, returns that port encoded in binary
Link to this section Types
Link to this section Functions
Returns a struct given an ip in binary form, plus an
udp_port or tcp_port.
Examples
iex> ExWire.Struct.Endpoint.decode([<<1,2,3,4>>, <<>>, <<5>>])
%ExWire.Struct.Endpoint{
ip: [1,2,3,4],
udp_port: nil,
tcp_port: 5,
}
Given an IPv4 or IPv6 address in binary form, returns the address in list form.
Examples
iex> ExWire.Struct.Endpoint.decode_ip(<<1,2,3,4>>)
[1, 2, 3, 4]
iex> ExWire.Struct.Endpoint.decode_ip(<<1::128>>)
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]
iex> ExWire.Struct.Endpoint.decode_ip(<<0xFF, 0xFF, 0xFF, 0xFF>>)
[255, 255, 255, 255]
iex> ExWire.Struct.Endpoint.decode_ip(<<127, 0, 0, 1>>)
[127, 0, 0, 1]
iex> ExWire.Struct.Endpoint.decode_ip(<<>>)
[]
Returns a port given a binary version of the port
as input. Note: we return nil for an empty or zero binary.
Examples
iex> ExWire.Struct.Endpoint.decode_port(<<>>)
nil
iex> ExWire.Struct.Endpoint.decode_port(<<0>>)
nil
iex> ExWire.Struct.Endpoint.decode_port(<<0, 0>>)
nil
iex> ExWire.Struct.Endpoint.decode_port(<<1>>)
1
iex> ExWire.Struct.Endpoint.decode_port(<<1, 0>>)
256
Versus decode/3, and given a module with an ip, a tcp_port and
a udp_port, returns a tuple of encoded values.
Examples
iex> ExWire.Struct.Endpoint.encode(%ExWire.Struct.Endpoint{ip: [1, 2, 3, 4], udp_port: nil, tcp_port: 5})
[<<1, 2, 3, 4>>, <<>>, <<0, 5>>]
Given an ip address that’s an encoded as a list, returns that address encoded as a binary.
Examples
iex> ExWire.Struct.Endpoint.encode_ip([1, 2, 3, 4])
<<1, 2, 3, 4>>
iex> ExWire.Struct.Endpoint.encode_ip([])
<<>>