Mads
Multi-Agent Distributed System
Loading...
Searching...
No Matches
Mads::LazyPayload Class Reference

A received message payload that lazily holds either its JSON text or its parsed nlohmann::json form, caching whichever is produced on first use. More...

#include <agent.hpp>

Public Member Functions

 LazyPayload ()=default
 
const std::string & text () const
 JSON text form (dumps the cached object once if only the object exists).
 
const nlohmann::json & doc () const
 Parsed object form (parses the cached text once if only text exists).
 

Static Public Member Functions

static LazyPayload from_text (std::string text)
 
static LazyPayload from_doc (nlohmann::json doc)
 

Detailed Description

A received message payload that lazily holds either its JSON text or its parsed nlohmann::json form, caching whichever is produced on first use.

receive() stores whichever representation it already has cheaply — the decoded object for MsgPack frames, the raw text for JSON frames — and the other form is produced only if a consumer asks for it. This avoids the decode -> dump -> re-parse round-trip on the hot receive path.

Conversions mutate cached state, so callers must serialise access (the Agent does so under its message-state mutex).

Definition at line 87 of file agent.hpp.

Constructor & Destructor Documentation

◆ LazyPayload()

Mads::LazyPayload::LazyPayload ( )
default

Member Function Documentation

◆ doc()

const nlohmann::json & Mads::LazyPayload::doc ( ) const
inline

Parsed object form (parses the cached text once if only text exists).

Examples
/home/runner/work/MADS/MADS/src/agent.hpp.

Definition at line 107 of file agent.hpp.

Referenced by from_doc().

◆ from_doc()

static LazyPayload Mads::LazyPayload::from_doc ( nlohmann::json  doc)
inlinestatic
Examples
/home/runner/work/MADS/MADS/src/agent.hpp.

Definition at line 95 of file agent.hpp.

References doc().

◆ from_text()

static LazyPayload Mads::LazyPayload::from_text ( std::string  text)
inlinestatic
Examples
/home/runner/work/MADS/MADS/src/agent.hpp.

Definition at line 90 of file agent.hpp.

References text().

◆ text()

const std::string & Mads::LazyPayload::text ( ) const
inline

JSON text form (dumps the cached object once if only the object exists).

Examples
/home/runner/work/MADS/MADS/src/agent.hpp.

Definition at line 101 of file agent.hpp.

Referenced by from_text().


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