ex_wire v0.1.1 ExWire.Message.Ping

A wrapper for ExWire’s Ping message.

Link to this section Summary

Functions

Decodes a given message binary, which is assumed to be an RLP encoded list of elements

Given a Ping message, encodes it so it can be sent on the wire in RLPx

Callback implementation for ExWire.Message.message_id/0

Ping messages specify a destination

Link to this section Types

Link to this type t()
t() :: %ExWire.Message.Ping{from: ExWire.Struct.Endpoint.t, timestamp: integer, to: ExWire.Struct.Endpoint.t, version: integer}

Link to this section Functions

Link to this function decode(data)
decode(binary) :: t

Decodes a given message binary, which is assumed to be an RLP encoded list of elements.

Examples

iex> ExWire.Message.Ping.decode([1, [<<1,2,3,4>>, <<>>, <<5>>], [<<5,6,7,8>>, <<6>>, <<>>], 4] |> ExRLP.encode)
%ExWire.Message.Ping{
  version: 1,
  from: %ExWire.Struct.Endpoint{ip: [1, 2, 3, 4], tcp_port: 5, udp_port: nil},
  to: %ExWire.Struct.Endpoint{ip: [5, 6, 7, 8], tcp_port: nil, udp_port: 6},
  timestamp: 4,
}

iex> ExWire.Message.Ping.decode([<<1>>] |> ExRLP.encode)
** (MatchError) no match of right hand side value: [<<1>>]
Link to this function encode(ping)
encode(t) :: binary

Given a Ping message, encodes it so it can be sent on the wire in RLPx.

Examples

iex> ExWire.Message.Ping.encode(%ExWire.Message.Ping{
...>   version: 1,
...>   from: %ExWire.Struct.Endpoint{ip: [1, 2, 3, 4], tcp_port: 5, udp_port: nil},
...>   to: %ExWire.Struct.Endpoint{ip: [5, 6, 7, 8], tcp_port: nil, udp_port: 6},
...>   timestamp: 4}
...> ) |> ExRLP.decode()
[<<1>>, [<<1, 2, 3, 4>>, "", <<0, 5>>], [<<5, 6, 7, 8>>, <<0, 6>>, ""], <<4>>]

Callback implementation for ExWire.Message.message_id/0.

Ping messages specify a destination.

Examples

iex> ExWire.Message.Ping.to(%ExWire.Message.Ping{
...>   version: 1,
...>   from: %ExWire.Struct.Endpoint{ip: [1, 2, 3, 4], tcp_port: 5, udp_port: nil},
...>   to: %ExWire.Struct.Endpoint{ip: [5, 6, 7, 8], tcp_port: nil, udp_port: 6},
...>   timestamp: 4}
...> )
%ExWire.Struct.Endpoint{ip: [5, 6, 7, 8], tcp_port: nil, udp_port: 6}