Fray Engine
Loading...
Searching...
No Matches
fray::message Namespace Reference

Namespaces

namespace  detail
 Internal helpers for big-endian encoding.

Classes

struct  Prefix
 Fixed-size routing prefix at the start of every frame; routers read only this. All integers are big-endian on the wire. Layout: 0 version | 1 destinationKind | 2-5 destinationId | 6 senderKind | 7-10 senderId 11-14 operationId | 15-18 length | 19-22 headerLength | 23-38 uid | 39 category. More...
struct  InData
 A parsed incoming message. The payload is a view into the frame, which this keeps alive via shared ownership. More...
struct  FrameOptions
 Everything FrameBuilder needs to build one outgoing Engine message. More...
class  FrameBuilder
 Builds outgoing frames sent by the Engine (sender is always the Engine). Stateless; safe to use from any thread. More...

Functions

bool isCommand (const Prefix &prefix, F_ulong id)
 Tests whether a prefix identifies a command.
bool isNotice (const Prefix &prefix, F_ulong id)
 Tests whether a prefix identifies a protocol notification.
bool isControl (const Prefix &prefix)
 Identifies readiness and health control frames.
bool isConsoleCommand (const Prefix &prefix)
 Identifies commands the Console shows as entries. Control traffic and the Console's own log and entry traffic are left out, or every line would produce another entry.
bool wantsLog (std::uint32_t flags)
 Tests whether a message's header flags leave it in the disk log.
bool wantsConsole (std::uint32_t flags)
 Tests whether a message's header flags leave it in the Console.
bool isTracked (const Prefix &prefix, std::uint32_t flags)
 Identifies messages the Engine router logs, shows in the Console, or both.
void encodePrefix (const Prefix &p, F_uchar *out)
 Serializes a prefix into its PREFIX_SIZE-byte big-endian wire form.
F_err decodePrefix (const F_uchar *data, size_t size, Prefix &out)
 Parses and validates a prefix from received bytes.
std::shared_ptr< const std::vector< F_uchar > > assignUid (const std::shared_ptr< const std::vector< F_uchar > > &frame, Prefix &prefix)
 Assigns a random 128-bit UID to a frame whose prefix does not have one. Existing UIDs are preserved; input frame bytes remain unchanged.
F_err buildFrame (Prefix prefix, const Header &header, const F_uchar *payload, size_t payloadSize, std::vector< F_uchar > &out)
 Builds a complete frame (prefix + protobuf header + payload) into a byte vector. The prefix's length and headerLength fields are filled in from the header and payload.
const char * processName (ProcessKind kind)
 Human-readable name of a process kind, also used as the header sender/destination name.
std::string processInstanceName (ProcessKind kind, std::uint32_t id)
 Names a process instance for readiness diagnostics.
uint64_t nextMessageId ()
 Returns the next message ID. Message IDs are unique per sender, so every engine message takes its ID from here. Thread-safe (atomic counter); starts at 1.
bool validMulticastRecipients (const Header &header)
 Validates the explicit destinations of a multicast header.
F_err parseFrame (std::shared_ptr< const std::vector< F_uchar > > frame, InData &out)
 Parses the header of a complete frame. The payload is not read or copied.

Variables

constexpr F_uchar PREFIX_VERSION = 0
 Wire format version written to, and required in, byte 0 of every prefix.
constexpr std::uint32_t PROTOCOL_VERSION = 0
 Version written to the protobuf message header.
constexpr std::uint32_t LOADING_WINDOW_ID = 0
 Renderer instance ID assigned to the loading window.
constexpr std::uint32_t MAIN_WINDOW_ID = 1
 Renderer instance ID assigned to the first application window.
constexpr size_t PREFIX_SIZE = 40
 Size in bytes of the fixed binary routing prefix.
constexpr F_ulong MAX_FRAME_LENGTH = 16 * 1024 * 1024
 Largest allowed value of the prefix length field (header + payload). Checked before any buffer is allocated.
constexpr std::uint32_t SILENT_FLAGS = MESSAGE_FLAG_NO_LOG | MESSAGE_FLAG_NO_CONSOLE

Function Documentation

◆ assignUid()

std::shared_ptr< const std::vector< F_uchar > > fray::message::assignUid ( const std::shared_ptr< const std::vector< F_uchar > > & frame,
Prefix & prefix )
inline

Assigns a random 128-bit UID to a frame whose prefix does not have one. Existing UIDs are preserved; input frame bytes remain unchanged.

Parameters
frameComplete validated frame.
prefixDecoded prefix, updated with the assigned UID.
Returns
Original frame if already assigned, otherwise a copy with its new UID.

Definition at line 282 of file message.hpp.

◆ buildFrame()

F_err fray::message::buildFrame ( Prefix prefix,
const Header & header,
const F_uchar * payload,
size_t payloadSize,
std::vector< F_uchar > & out )
inline

Builds a complete frame (prefix + protobuf header + payload) into a byte vector. The prefix's length and headerLength fields are filled in from the header and payload.

Parameters
prefixRouting prefix, taken by value; its length fields are overwritten.
headerProtobuf header to serialize.
payloadOpaque payload bytes; may be null only when payloadSize is 0.
payloadSizeNumber of payload bytes.
outReceives the frame only on success.
Returns
errors::NONE on success; INVALID_MESSAGE for an invalid category, sizes, payload, or header serialization; UNSUPPORTED_MESSAGE_VERSION for an unsupported message version, or MESSAGE_TOO_LARGE if the frame exceeds the limit.

Definition at line 306 of file message.hpp.

◆ decodePrefix()

F_err fray::message::decodePrefix ( const F_uchar * data,
size_t size,
Prefix & out )
inline

Parses and validates a prefix from received bytes.

Parameters
dataStart of the received bytes.
sizeNumber of bytes available at data.
outReceives the prefix only when NONE is returned; untouched otherwise.
Returns
errors::NONE on success; INVALID_MESSAGE if the category or lengths are invalid; UNSUPPORTED_MESSAGE_VERSION if the version byte is not PREFIX_VERSION; MESSAGE_TOO_LARGE if length exceeds MAX_FRAME_LENGTH.

Definition at line 243 of file message.hpp.

◆ encodePrefix()

void fray::message::encodePrefix ( const Prefix & p,
F_uchar * out )
inline

Serializes a prefix into its PREFIX_SIZE-byte big-endian wire form.

Parameters
pPrefix to write.
outDestination buffer; must hold at least PREFIX_SIZE bytes.

Definition at line 219 of file message.hpp.

◆ isCommand()

bool fray::message::isCommand ( const Prefix & prefix,
F_ulong id )
inline

Tests whether a prefix identifies a command.

Parameters
prefixDecoded routing prefix.
idCommand identifier to match.
Returns
True only for the matching command category and identifier.

Definition at line 81 of file message.hpp.

◆ isConsoleCommand()

bool fray::message::isConsoleCommand ( const Prefix & prefix)
inline

Identifies commands the Console shows as entries. Control traffic and the Console's own log and entry traffic are left out, or every line would produce another entry.

Parameters
prefixDecoded routing prefix.
Returns
True for commands that get a Console entry and a disk log record under their UID.

Definition at line 119 of file message.hpp.

◆ isControl()

bool fray::message::isControl ( const Prefix & prefix)
inline

Identifies readiness and health control frames.

Parameters
prefixDecoded routing prefix.
Returns
True for readiness announcements, probes, pings, and pongs.

Definition at line 106 of file message.hpp.

◆ isNotice()

bool fray::message::isNotice ( const Prefix & prefix,
F_ulong id )
inline

Tests whether a prefix identifies a protocol notification.

Parameters
prefixDecoded routing prefix.
idNotification identifier to match.
Returns
True only for the matching message category and identifier.

Definition at line 94 of file message.hpp.

◆ isTracked()

bool fray::message::isTracked ( const Prefix & prefix,
std::uint32_t flags )
inline

Identifies messages the Engine router logs, shows in the Console, or both.

Parameters
prefixDecoded routing prefix.
flagsHeader flags (MessageFlag bits).
Returns
True for console commands that have not opted out of both the log and the Console.

Definition at line 157 of file message.hpp.

◆ nextMessageId()

uint64_t fray::message::nextMessageId ( )
inline

Returns the next message ID. Message IDs are unique per sender, so every engine message takes its ID from here. Thread-safe (atomic counter); starts at 1.

Returns
A new, never-reused ID.

Definition at line 385 of file message.hpp.

◆ parseFrame()

F_err fray::message::parseFrame ( std::shared_ptr< const std::vector< F_uchar > > frame,
InData & out )
inline

Parses the header of a complete frame. The payload is not read or copied.

Parameters
frameComplete frame (prefix + header + payload); the result shares ownership of it.
outReceives the parsed message only on success.
Returns
errors::NONE on success; INVALID_MESSAGE if frame is null, the size does not match the prefix length, or the header fails to parse; UNSUPPORTED_MESSAGE_VERSION for an unsupported prefix or message version, or MESSAGE_TOO_LARGE from decodePrefix.

Definition at line 511 of file message.hpp.

◆ processInstanceName()

std::string fray::message::processInstanceName ( ProcessKind kind,
std::uint32_t id )
inline

Names a process instance for readiness diagnostics.

Parameters
kindProcess kind.
idProcess instance ID.
Returns
Diagnostic label including IDs for renderers and plug-ins.

Definition at line 364 of file message.hpp.

◆ processName()

const char * fray::message::processName ( ProcessKind kind)
inline

Human-readable name of a process kind, also used as the header sender/destination name.

Parameters
kindProcess kind to name.
Returns
Static string such as "Engine" or "Electron Main"; "Unknown" for unlisted kinds.

Definition at line 342 of file message.hpp.

◆ validMulticastRecipients()

bool fray::message::validMulticastRecipients ( const Header & header)
inline

Validates the explicit destinations of a multicast header.

Parameters
headerDecoded header containing the recipient list.
Returns
True when the list is nonempty, contains valid process kinds, and has no duplicates.

Definition at line 431 of file message.hpp.

◆ wantsConsole()

bool fray::message::wantsConsole ( std::uint32_t flags)
inline

Tests whether a message's header flags leave it in the Console.

Parameters
flagsHeader flags (MessageFlag bits).
Returns
False when MESSAGE_FLAG_NO_CONSOLE is set.

Definition at line 145 of file message.hpp.

◆ wantsLog()

bool fray::message::wantsLog ( std::uint32_t flags)
inline

Tests whether a message's header flags leave it in the disk log.

Parameters
flagsHeader flags (MessageFlag bits).
Returns
False when MESSAGE_FLAG_NO_LOG is set.

Definition at line 134 of file message.hpp.

Variable Documentation

◆ LOADING_WINDOW_ID

std::uint32_t fray::message::LOADING_WINDOW_ID = 0
constexpr

Renderer instance ID assigned to the loading window.

Definition at line 38 of file message.hpp.

◆ MAIN_WINDOW_ID

std::uint32_t fray::message::MAIN_WINDOW_ID = 1
constexpr

Renderer instance ID assigned to the first application window.

Definition at line 40 of file message.hpp.

◆ MAX_FRAME_LENGTH

F_ulong fray::message::MAX_FRAME_LENGTH = 16 * 1024 * 1024
constexpr

Largest allowed value of the prefix length field (header + payload). Checked before any buffer is allocated.

Definition at line 44 of file message.hpp.

◆ PREFIX_SIZE

size_t fray::message::PREFIX_SIZE = 40
constexpr

Size in bytes of the fixed binary routing prefix.

Definition at line 42 of file message.hpp.

◆ PREFIX_VERSION

F_uchar fray::message::PREFIX_VERSION = 0
constexpr

Wire format version written to, and required in, byte 0 of every prefix.

Definition at line 34 of file message.hpp.

◆ PROTOCOL_VERSION

std::uint32_t fray::message::PROTOCOL_VERSION = 0
constexpr

Version written to the protobuf message header.

Definition at line 36 of file message.hpp.

◆ SILENT_FLAGS

std::uint32_t fray::message::SILENT_FLAGS = MESSAGE_FLAG_NO_LOG | MESSAGE_FLAG_NO_CONSOLE
constexpr

Flags for frames that are neither logged nor shown in the Console: readiness and health traffic, and the shutdown command.

Definition at line 392 of file message.hpp.