Fray Engine
Loading...
Searching...
No Matches
message.hpp File Reference
#include <algorithm>
#include <array>
#include <atomic>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <limits>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <vector>
#include "errors.hpp"
#include "fray.pb.h"
#include "types.hpp"
#include "uid.hpp"

Go to the source code of this file.

Classes

struct  fray::message::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  fray::message::InData
 A parsed incoming message. The payload is a view into the frame, which this keeps alive via shared ownership. More...
struct  fray::message::FrameOptions
 Everything FrameBuilder needs to build one outgoing Engine message. More...
class  fray::message::FrameBuilder
 Builds outgoing frames sent by the Engine (sender is always the Engine). Stateless; safe to use from any thread. More...

Namespaces

namespace  fray
namespace  fray::message
namespace  fray::message::detail
 Internal helpers for big-endian encoding.

Functions

bool fray::message::isCommand (const Prefix &prefix, F_ulong id)
 Tests whether a prefix identifies a command.
bool fray::message::isNotice (const Prefix &prefix, F_ulong id)
 Tests whether a prefix identifies a protocol notification.
bool fray::message::isControl (const Prefix &prefix)
 Identifies readiness and health control frames.
bool fray::message::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 fray::message::wantsLog (std::uint32_t flags)
 Tests whether a message's header flags leave it in the disk log.
bool fray::message::wantsConsole (std::uint32_t flags)
 Tests whether a message's header flags leave it in the Console.
bool fray::message::isTracked (const Prefix &prefix, std::uint32_t flags)
 Identifies messages the Engine router logs, shows in the Console, or both.
void fray::message::detail::put32 (F_uchar *out, F_ulong v)
 Writes a 32-bit value as 4 big-endian bytes.
F_ulong fray::message::detail::get32 (const F_uchar *in)
 Reads 4 big-endian bytes as a 32-bit value.
void fray::message::encodePrefix (const Prefix &p, F_uchar *out)
 Serializes a prefix into its PREFIX_SIZE-byte big-endian wire form.
F_err fray::message::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 > > fray::message::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 fray::message::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 * fray::message::processName (ProcessKind kind)
 Human-readable name of a process kind, also used as the header sender/destination name.
std::string fray::message::processInstanceName (ProcessKind kind, std::uint32_t id)
 Names a process instance for readiness diagnostics.
uint64_t fray::message::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 fray::message::validMulticastRecipients (const Header &header)
 Validates the explicit destinations of a multicast header.
F_err fray::message::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 fray::message::PREFIX_VERSION = 0
 Wire format version written to, and required in, byte 0 of every prefix.
constexpr std::uint32_t fray::message::PROTOCOL_VERSION = 0
 Version written to the protobuf message header.
constexpr std::uint32_t fray::message::LOADING_WINDOW_ID = 0
 Renderer instance ID assigned to the loading window.
constexpr std::uint32_t fray::message::MAIN_WINDOW_ID = 1
 Renderer instance ID assigned to the first application window.
constexpr size_t fray::message::PREFIX_SIZE = 40
 Size in bytes of the fixed binary routing prefix.
constexpr F_ulong fray::message::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 fray::message::SILENT_FLAGS = MESSAGE_FLAG_NO_LOG | MESSAGE_FLAG_NO_CONSOLE