dfx 0.1.0
Linux-based dynamic dataflow executor
Loading...
Searching...
No Matches
dfx::Core::DataMessage Class Reference

Data-plane message containing an owned byte buffer. More...

#include <dfx-core/messages/DataMessage.hpp>

Inheritance diagram for dfx::Core::DataMessage:
[legend]
Collaboration diagram for dfx::Core::DataMessage:
[legend]

Public Member Functions

std::vector< uint8_t > const & data () const noexcept
 Access the payload buffer.
std::vector< uint8_t > takeData () noexcept
 Move the payload buffer out of the message.
Kind kind () const override
 This message belongs to the data-plane connectivity domain.
MessagePtr clone () const override
 Clone this message (deep copy).
Public Member Functions inherited from dfx::Core::Message
 DISABLE_COPY_AND_MOVE (Message)
 Messages are non-copyable and non-movable.
virtual ~Message ()
 Virtual destructor.
template<typename Clock = std::chrono::steady_clock>
requires std::chrono::is_clock_v<Clock>
std::chrono::time_point< Clock, std::chrono::microseconds > timestampToTimePoint () const noexcept
 Convert timestamp() into a time_point of the given clock type.
void addToPathTaken (std::string path)
 Append one hop to the message path trace.
template<DerivedFromMessage T>
bool is () const noexcept
 Check whether this message is of a given derived type.
template<DerivedFromMessage T>
T & as () noexcept
 Cast this message to a derived type (unchecked).
template<DerivedFromMessage T>
T const & as () const noexcept
 Cast this message to a derived type (unchecked).
Utils::UUID const & uuid () const noexcept
 Unique identifier of this message instance.
Utils::UUID const & parentUuid () const noexcept
 UUID of the parent message if created from one, otherwise default UUID value.
std::vector< std::string > const & pathTaken () const noexcept
 Sequence of "node.port" hops this message has traversed.
std::chrono::microseconds timestamp () const noexcept
 Construction timestamp in microseconds since timestampClock epoch. This is not "wall clock time" unless timestampClock is CLOCK_REALTIME.
bool hasMimeType () const noexcept
 Whether the message carries an explicit MIME type.
MimeType mimeType () const noexcept
 Get the message MIME type. If no explicit MIME type is set, returns dfx::Core::MimeType::OctetStream.
void setMimeType (MimeType mimeType)
 Set the message MIME type.
void resetMimeType ()
 Clear the explicit MIME type (message then defaults to octet-stream).

Protected Member Functions

void cloneFromBase (Message const &base) override
 Copy base and derived state from base into this instance.
 DataMessage (std::vector< uint8_t > data, MessagePtr const &parent=nullptr)
 Construct a data message with a payload, optionally inheriting from a parent.
 DataMessage (std::vector< uint8_t > data, MimeType mimeType, MessagePtr const &parent=nullptr)
 Construct a data message with payload and explicit MIME type.
 Message (MessagePtr const &parent=nullptr)
 Construct a message, optionally inheriting state from a parent message.
 Message (MimeType mimeType, MessagePtr const &parent=nullptr)
 Construct a message with an explicit MIME type, optionally inheriting from a parent.
Protected Member Functions inherited from dfx::Core::Message
 Message (MessagePtr const &parent=nullptr)
 Construct a message, optionally inheriting state from a parent message.
 Message (MimeType mimeType, MessagePtr const &parent=nullptr)
 Construct a message with an explicit MIME type, optionally inheriting from a parent.

Friends

class Message

Additional Inherited Members

Static Public Member Functions inherited from dfx::Core::Message
template<DerivedFromMessage T, typename ... Args>
static std::unique_ptr< T > create (Args &&... args)
 Convenience allocator for derived message types.
Static Public Attributes inherited from dfx::Core::Message
static clockid_t timestampClock
 Clock used by the constructor to capture timestamps.

Detailed Description

Data-plane message containing an owned byte buffer.

Payload ownership
The message owns its payload buffer:
  • data() returns a const view of the internal std::vector<uint8_t>.
  • takeData() moves the buffer out, leaving the message with an empty payload.
MIME type
MIME type is handled by the base Message :
  • The constructor overload that takes a MimeType sets an explicit MIME type (Message(mimeType, parent)).
  • The other overload inherits base state from parent (UUID parent link, and optional MIME type) but does not force a MIME type.
Note
The base class forbids MimeType::Any on messages (asserted in Message).
Cloning
clone() produces a new DataMessage and copies:
  • all base fields via Message::cloneFromBase(...)
  • the payload buffer (_data)
Note
In dfx, fan-out delivery relies on cloning so each channel gets an independent message instance.

Constructor & Destructor Documentation

◆ DataMessage() [1/2]

dfx::Core::DataMessage::DataMessage ( std::vector< uint8_t > data,
MessagePtr const & parent = nullptr )
protected

Construct a data message with a payload, optionally inheriting from a parent.

Parameters
dataPayload bytes (moved into the message).
parentOptional parent message. Base state (parent UUID, and optional MIME type) is inherited from the parent via Message(parent).

◆ DataMessage() [2/2]

dfx::Core::DataMessage::DataMessage ( std::vector< uint8_t > data,
MimeType mimeType,
MessagePtr const & parent = nullptr )
protected

Construct a data message with payload and explicit MIME type.

Parameters
dataPayload bytes (moved into the message).
mimeTypeExplicit MIME type to assign (must not be Any, asserted by Message).
parentOptional parent message whose UUID/MIME-type are inherited.

Member Function Documentation

◆ clone()

MessagePtr dfx::Core::DataMessage::clone ( ) const
overridevirtual

Clone this message (deep copy).

The clone copies the base state and duplicates the payload vector.

Returns
A new message instance of the same dynamic type.

Implements dfx::Core::Message.

◆ cloneFromBase()

void dfx::Core::DataMessage::cloneFromBase ( Message const & base)
overrideprotectedvirtual

Copy base and derived state from base into this instance.

Calls Message::cloneFromBase(base) then copies the payload from base.as<DataMessage>()._data.

Reimplemented from dfx::Core::Message.

◆ data()

std::vector< uint8_t > const & dfx::Core::DataMessage::data ( ) const
inlinenoexcept

Access the payload buffer.

Returns
A const reference to the owned byte vector.

◆ kind()

Kind dfx::Core::DataMessage::kind ( ) const
inlineoverridevirtual

This message belongs to the data-plane connectivity domain.

Implements dfx::Core::Message.

◆ Message() [1/2]

dfx::Core::Message::Message ( MessagePtr const & parent = nullptr)
protected

Construct a message, optionally inheriting state from a parent message.

Captures a timestamp and generates a new UUID.

If parent is non-null:

  • parentUuid() becomes the parent's UUID
  • MIME type (if any) is inherited
Parameters
parentOptional parent message (non-owning reference through pointer).

◆ Message() [2/2]

dfx::Core::Message::Message ( MimeType mimeType,
MessagePtr const & parent = nullptr )
protected

Construct a message with an explicit MIME type, optionally inheriting from a parent.

Equivalent to Message(MessagePtr const&) followed by setMimeType.

Parameters
mimeTypeConcrete MIME type to assign (must not be Any, asserted).
parentOptional parent message.

◆ takeData()

std::vector< uint8_t > dfx::Core::DataMessage::takeData ( )
inlinenoexcept

Move the payload buffer out of the message.

After this call, the message’s internal payload becomes empty.

Returns
The owned byte vector (moved).

The documentation for this class was generated from the following file: