![]() |
Mads
Multi-Agent Distributed System
|
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) |
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).
|
default |
|
inline |
Parsed object form (parses the cached text once if only text exists).
Definition at line 107 of file agent.hpp.
Referenced by from_doc().
|
inlinestatic |
|
inlinestatic |
|
inline |
JSON text form (dumps the cached object once if only the object exists).
Definition at line 101 of file agent.hpp.
Referenced by from_text().