Skip to main content

Message

Struct Message 

Source
pub struct Message {
    pub context: OwnedDataValue,
    /* private fields */
}
Expand description

A message flowing through the dataflow engine.

Construct via Message::builder for the full API, or use the shortcuts Message::new (already-owned Arc<OwnedDataValue> payload — the perf path) and Message::from_value (bridges from serde_json::Value).

context is held as an OwnedDataValue tree (not serde_json::Value) so the JSONLogic evaluator can borrow it into its arena via OwnedDataValue::to_arena with a single deep walk in, and project the result back via DataValue::to_owned with a single deep walk out — no serde_json::Value round-trip in the hot path. The on-the-wire JSON shape is preserved by datavalue’s native Serialize / Deserialize impls.

Every other field is encapsulated — read via id(), payload(), audit_trail(), errors(), capture_changes(); mutate errors via Message::add_error; mutate context via crate::TaskContext::set. Direct mutation of audit_trail is engine-internal.

Fields§

§context: OwnedDataValue

Unified context containing data, metadata, and temp_data keys. Always an OwnedDataValue::Object; the engine populates the three top-level keys at construction. Public for read access (tests do message.context["data"]["x"] lookups); inside handlers prefer crate::TaskContext::set which records audit-trail changes.

Implementations§

Source§

impl Message

Source

pub fn builder() -> MessageBuilder

Start building a message. The recommended constructor — chains .id(...), .payload(...) / .payload_json(...), and .capture_changes(...) calls, then .build().

Source

pub fn new(payload: Arc<OwnedDataValue>) -> Self

Construct a message from an already-owned payload Arc. The perf path: zero serde_json::Value walk, one Arc refcount bump per message. Use this from a hot loop with a payload Arc shared across messages (e.g. a benchmark harness or an HTTP handler that receives already-parsed payloads).

Source

pub fn from_value(payload: &JsonValue) -> Self

Construct a message from a serde_json::Value payload. Convenience for code that already speaks serde_json; goes through the OwnedDataValue::from(&Value) bridge (one deep walk).

Source

pub fn from_json_str(payload: &str) -> Result<Self>

Construct a message from a JSON payload string. Parses with serde_json and bridges into OwnedDataValue. Returns DataflowError::Deserialization on parse failure.

Source

pub fn add_error(&mut self, error: ErrorInfo)

Add an error to the message

Source

pub fn has_errors(&self) -> bool

Check if message has errors

Source

pub fn id(&self) -> &str

Message id (UUID v7 string by default; caller-supplied if set via MessageBuilder::id).

Source

pub fn payload(&self) -> &OwnedDataValue

Original payload as the engine received it. Immutable for the lifetime of the message — the engine reads it through this Arc and copies into context only as needed by handlers.

Source

pub fn payload_arc(&self) -> &Arc<OwnedDataValue>

The shared payload Arc itself. Useful when forwarding the same payload to multiple messages without recloning the underlying OwnedDataValue tree.

Source

pub fn audit_trail(&self) -> &[AuditTrail]

Audit-trail entries recorded by the engine, one per task that ran (skipped tasks are absent unless Trace mode is on).

Source

pub fn errors(&self) -> &[ErrorInfo]

Errors collected while processing — both validation failures and task errors that the workflow swallowed via continue_on_error.

Source

pub fn capture_changes(&self) -> bool

Whether per-write Change capture is on. When false, audit-trail entries are still emitted but their changes lists are empty — the bulk-pipeline fast path.

Source

pub fn data(&self) -> &OwnedDataValue

Get a reference to the data field in context. Returns &OwnedDataValue::Null if missing (matches serde_json::Value’s Index fallback semantics).

Source

pub fn metadata(&self) -> &OwnedDataValue

Get a reference to the metadata field in context.

Source

pub fn temp_data(&self) -> &OwnedDataValue

Get a reference to the temp_data field in context.

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Message

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Message

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.