diff options
| author | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-11-07 14:57:56 +0100 |
|---|---|---|
| committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2026-11-07 14:57:56 +0100 |
| commit | 55446448c0cd836241e8731d6af5091f0a82a14f (patch) | |
| tree | 635f8b503014f21558e42fe1cd7f851546e0cf9d /modules/codec-json/c++/json.hpp | |
| parent | 97ae1a8f23074fea3784a008921c5d9fc3c1e8fb (diff) | |
| download | forstio-forstio-55446448c0cd836241e8731d6af5091f0a82a14f.tar.gz | |
Reintroduced non strict mode
Diffstat (limited to 'modules/codec-json/c++/json.hpp')
| -rw-r--r-- | modules/codec-json/c++/json.hpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/modules/codec-json/c++/json.hpp b/modules/codec-json/c++/json.hpp index 1da74b1..a982bf3 100644 --- a/modules/codec-json/c++/json.hpp +++ b/modules/codec-json/c++/json.hpp @@ -66,6 +66,12 @@ struct codec_config<encode::Json> { uint64_t depth = 16u; uint64_t length = 4096u; bool pretty = false; + /** + * Strict decoding demands a fully described dataset. + * Every member of a Struct has to be present in the json data. + * Non strict decoding is the default, since configuration files + * usually only describe the deviations from the default values. + */ bool strict = false; bool is_within(uint64_t bytes, uint64_t d){ @@ -117,7 +123,7 @@ public: buffer_view buff_v{from_decode.get_buffer()}; impl::json_helper::skip_whitespace(buff_v); - auto eov = impl::json_decode<Schema, ToEncoding>::decode(buff_v, to_decode); + auto eov = impl::json_decode<Schema, ToEncoding>::decode(buff_v, to_decode, cfg_); if(eov.is_error()){ return std::move(eov.get_error()); } @@ -129,6 +135,15 @@ public: void set_pretty(bool pretty){ cfg_.pretty = pretty; } + + /** + * Strict decoding demands a fully described dataset. + * Non strict decoding allows missing struct members, which keep + * their default value in that case. + */ + void set_strict(bool strict){ + cfg_.strict = strict; + } }; } |
