View Source Xander.Util (Xander v0.2.0)

Summary

Functions

Unwrap the multiplexer header from a CDDL message. This can be used to extract the payload from node responses.

Unwrap the multiplexer header from a CDDL message and return just the result. Raises an error if the input is invalid.

Add multiplexer header to a CBOR payload. This is used to format outgoing messages to the Cardano node.

Functions

plex(msg)

@spec plex(binary() | nil) :: {:ok, map()} | {:error, atom()}

Unwrap the multiplexer header from a CDDL message. This can be used to extract the payload from node responses.

Examples

iex> Xander.Util.plex(<<0, 0, 0, 0, 1, 2, 0, 3, 97, 98, 99>>)
{:ok, %{size: <<0, 3>>, payload: "abc", protocol_id: <<1, 2>>}}

plex!(msg)

@spec plex!(binary()) :: map()

Unwrap the multiplexer header from a CDDL message and return just the result. Raises an error if the input is invalid.

Examples

iex> Xander.Util.plex!(<<0, 0, 0, 0, 1, 2, 0, 3, 97, 98, 99>>)
%{payload: <<97, 98, 99>>, protocol_id: <<1, 2>>, size: <<0, 3>>}

plex_encode(payload)

@spec plex_encode(binary()) :: binary()

Add multiplexer header to a CBOR payload. This is used to format outgoing messages to the Cardano node.

Examples

iex> Xander.Util.plex_encode(<<97, 98, 99>>)
<<0, 0, 0, 0, 0, 2, 0, 3, 97, 98, 99>>