MessageLib
Library for formatting the various messages supported by Origin and Destination.
Message memory layout
Position | Field | Type | Bytes | Description |
---|---|---|---|---|
[000..017) | header | uint136 | 17 | Encoded general routing information for the message |
[017..AAA) | body | bytes | ?? | 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
Name | Type | Description |
---|---|---|
header_ | Header | Encoded general routing information for the message |
body_ | bytes | Formatted payload (according to flag) with message body |
Returns
Name | Type | Description |
---|---|---|
<none> | bytes | Formatted 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);
header
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);