|
morph 0.1.0
Asynchronous bridge between GUI thread and business models
|
The LogEntry JSON codec, kept apart from action_log.hpp. More...
#include <glaze/glaze.hpp>#include <string>#include <string_view>#include "action_log.hpp"Go to the source code of this file.
Classes | |
| struct | morph::journal::detail::EscapingWriteOpts |
| Write options that escape ASCII control bytes as \\uXXXX sequences. More... | |
Functions | |
| void | morph::journal::detail::throwOnGlazeError (const glz::error_ctx &errCode, std::string_view context) |
Converts a Glaze error into a SerializationError, or does nothing if errCode reports success. | |
| std::string | morph::journal::toJson (const LogEntry &entry) |
Encodes entry as JSON. | |
| LogEntry | morph::journal::fromJson (std::string_view json) |
Decodes json into a LogEntry. | |
The LogEntry JSON codec, kept apart from action_log.hpp.
action_log.hpp defines LogEntry, Outcome, IActionLog and the process-wide log slot; core/model.hpp includes it for IActionLog alone. Were the codec declared there too, every consumer that reaches a model would compile <glaze/glaze.hpp> whether or not it ever serialised anything, and that is a measured cliff rather than a tidiness point: with glaze included, action_log.hpp is 252,559 preprocessed lines and 2.67 CPU-s, against core/strand.hpp's 127,217 and 1.20.
Include this header instead when you need toJson/fromJson. Inside morph, exactly one header does: file_action_log.hpp.
Definition in file action_log_json.hpp.
|
inline |
Converts a Glaze error into a SerializationError, or does nothing if errCode reports success.
Shared by toJson and fromJson on purpose, not just for DRY: this is one non-template function, so both call through the exact same compiled branch. fromJson's failure path is easy to exercise for real (malformed JSON is everyday input); toJson's is not — Glaze's buffer-writer has no reachable failure mode for a flat struct of strings/integers like LogEntry (its only write-relevant error codes are for recursion-depth limits LogEntry can't hit, and dump_int_error, which nothing in Glaze's own source ever actually raises). Routing both through here means toJson's error branch is the same branch fromJson's test already exercises, rather than a second, structurally-unreachable copy of the same three lines.
| errCode | Result of a glz::write_json/glz::read_json call. |
| context | Buffer or input passed to glz::format_error for the message. |
Definition at line 53 of file action_log_json.hpp.
|
inline |
Encodes entry as JSON.
LogEntry is a plain aggregate, so Glaze reflects it without a glz::meta specialisation of its own — the same automatic reflection BRIDGE_REGISTER_ACTION relies on for user action structs. (Its outcome field is Outcome, which does have a glz::meta — see above — so it reads back as "Succeeded"/"Failed", not 0/1.) Used by sinks that need an opaque string representation (FileActionLog).
Writes with detail::EscapingWriteOpts so a raw ASCII control byte in any string field (entityKey, payload, error, principal, idempotencyKey) round-trips through fromJson instead of producing invalid or silently corrupted JSON — see that struct's doc comment.
| entry | Entry to encode. |
| SerializationError | on encode failure (see detail::throwOnGlazeError for why this is not realistically reachable for LogEntry). |
Definition at line 97 of file action_log_json.hpp.
|
inline |
Decodes json into a LogEntry.
Reads leniently: glz::read<glz::opts{.error_on_unknown_keys = false}>, the same stance morph::wire::decode takes (include/morph/core/wire.hpp) — an unknown/extra JSON key (e.g. an additive field written by a newer morph build) is ignored rather than rejected. Same duplicate-key caveat as wire::decode: last-wins, not a security boundary (glaze offers no reject option). Syntactically malformed JSON still throws. After a successful decode, also enforces the line-format version rule: v <= kLogFormatVersion decodes normally, v greater than this build's kLogFormatVersion throws — a build refuses to guess at a line format newer than any it has seen.
| json | One JSON-encoded entry, as toJson wrote it. |
| SerializationError | if json is not valid JSON, does not decode into a LogEntry, or decodes with v greater than kLogFormatVersion. |
Definition at line 119 of file action_log_json.hpp.