MessageLib

Git Source

Library for formatting the various messages supported by Origin and Destination.

Message memory layout

PositionFieldTypeBytesDescription
[000..017)headeruint13617Encoded general routing information for the message
[017..AAA)bodybytes??Formatted payload (according to flag) with message body

State Variables

OFFSET_HEADER

The variables below are not supposed to be used outside of the library directly.

uint256 private constant OFFSET_HEADER = 0;

OFFSET_BODY

uint256 private constant OFFSET_BODY = OFFSET_HEADER + HEADER_LENGTH;

Functions

formatMessage

Returns formatted message with provided fields.

function formatMessage(Header header_, bytes memory body_) internal pure returns (bytes memory);

Parameters

NameTypeDescription
header_HeaderEncoded general routing information for the message
body_bytesFormatted payload (according to flag) with message body

Returns

NameTypeDescription
<none>bytesFormatted message

castToMessage

Returns a Message view over for the given payload.

Will revert if the payload is not a message payload.

function castToMessage(bytes memory payload) internal pure returns (Message);

castToMessage

Casts a memory view to a Message view.

Will revert if the memory view is not over a message payload.

function castToMessage(MemView memView) internal pure returns (Message);

isMessage

Checks that a payload is a formatted Message.

function isMessage(MemView memView) internal pure returns (bool);

unwrap

Convenience shortcut for unwrapping a view.

function unwrap(Message message) internal pure returns (MemView);

leaf

Returns message's hash: a leaf to be inserted in the Merkle tree.

function leaf(Message message) internal pure returns (bytes32);

Returns message's encoded header field.

function header(Message message) internal pure returns (Header);

body

Returns message's body field as an untyped memory view.

function body(Message message) internal pure returns (MemView);

_header

Returns message's padded header without checking that it is a valid header.

function _header(MemView memView) private pure returns (uint256);

_body

Returns an untyped memory view over the body field without checking if the whole payload or the body are properly formatted.

function _body(MemView memView) private pure returns (MemView);