|
VoltMod
C++23 framework for CS2 server plugins
|
System.Text.Json-style helpers for mapping C++ types to and from JSON. More...
#include <Json.hpp>
Classes | |
| struct | PrettyOpts |
Static Public Member Functions | |
| template<class T , auto Options = ReadOptions> | |
| static Result< T > | ReadFile (std::string_view path) |
Parse path (resolved via ResolvePath) into T. | |
| template<class T , auto Options = ReadOptions> | |
| static Result< T > | Read (std::string_view text) |
| As ReadFile, over text already in hand. | |
| template<class T > | |
| static std::string | WritePretty (const T &value) |
Serialize value as prettified JSON. | |
| template<class T , auto Options = glz::opts{}> | |
| static std::string | Write (const T &value) |
Serialize value as compact JSON. | |
| static Result< glz::generic > | ParseDocument (std::string_view text) |
| Parse free-form JSON whose shape is not known at compile time. | |
| static void | SubstituteTokens (glz::generic &node, const Tokens &tokens) |
Recursively replace {key} tokens in every string value of node. | |
| static std::string | GetStringByPath (std::string_view jsonText, std::string_view dotPath) |
Descend a dot-separated path (e.g. "data.room.code") in jsonText. | |
| static std::string | GetString (const glz::generic &root, std::string_view dotPath) |
Static Public Attributes | |
| static constexpr glz::opts | ReadOptions {.comments = true, .error_on_unknown_keys = false} |
| static constexpr glz::opts | StrictReadOptions {.comments = true} |
| static constexpr PrettyOpts | PrettyOptions {{.prettify = true}, 2} |
System.Text.Json-style helpers for mapping C++ types to and from JSON.
Glaze reflects public aggregate members directly: the member name is the JSON key and a missing key keeps the member's C++ initializer. Unknown keys are ignored for compatibility with older settings files. No registration macro is needed.
|
inlinestatic |
As above, for a node already parsed: saves callers a dump-and-reparse round trip.
Definition at line 162 of file Json.hpp.
References ReadFile().
Referenced by GetStringByPath().
|
inlinestatic |
Descend a dot-separated path (e.g. "data.room.code") in jsonText.
jsonText does not parse, the path is absent, or the leaf is neither a string nor a primitive. A numeric or boolean leaf reads as "42" / "true" without quotes. Definition at line 151 of file Json.hpp.
References GetString(), ParseDocument(), and ReadFile().
Parse free-form JSON whose shape is not known at compile time.
Definition at line 108 of file Json.hpp.
References VoltMod::Error::Invalid(), and ReadFile().
Referenced by VoltMod::StatusService::BuildText(), GetStringByPath(), and VoltMod::Translations::Load().
As ReadFile, over text already in hand.
Definition at line 64 of file Json.hpp.
References VoltMod::Error::Invalid(), ReadFile(), and VoltMod::T.
|
inlinestatic |
Parse path (resolved via ResolvePath) into T.
Definition at line 46 of file Json.hpp.
References VoltMod::Error::Invalid(), VoltMod::ReadAllText(), and ReadFile().
Referenced by VoltMod::InstalledPlugins::Discover(), VoltMod::GameDataTable::GameDataTable(), GetString(), GetStringByPath(), VoltMod::Options< TSettings, TSnapshot >::Load(), ParseDocument(), Read(), ReadFile(), SubstituteTokens(), Write(), VoltMod::WriteGameDataRecord(), and WritePretty().
|
inlinestatic |
Recursively replace {key} tokens in every string value of node.
Substituting inside the parsed document rather than in its text is what keeps a token value containing " or \ (a player name, say) from producing invalid JSON.
Definition at line 122 of file Json.hpp.
References ReadFile(), SubstituteTokens(), and VoltMod::Strings::SubstituteTokens().
Referenced by SubstituteTokens().
Serialize value as compact JSON.
Definition at line 96 of file Json.hpp.
References VoltMod::Log::Error(), and ReadFile().
Referenced by VoltMod::StatusService::BuildJson().
Serialize value as prettified JSON.
For a file a human reviews: one value per line keeps a git diff of a regenerated artifact down to the values that actually changed.
Definition at line 89 of file Json.hpp.
References ReadFile().
Referenced by VoltMod::Schema::WriteDumpFile(), and VoltMod::WriteGameDataRecord().
|
staticconstexpr |
|
staticconstexpr |