mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-02 16:16:19 +08:00
add yyjson_read_flag symmetric to the yyjson_write_flag, so that non standard json's can be both written and read (#374)
This commit is contained in:
@@ -9,9 +9,9 @@ namespace rfl {
|
|||||||
namespace json {
|
namespace json {
|
||||||
|
|
||||||
template <class T, class... Ps>
|
template <class T, class... Ps>
|
||||||
Result<T> load(const std::string& _fname) {
|
Result<T> load(const std::string& _fname, const yyjson_read_flag _flag = 0) {
|
||||||
const auto read_string = [](const auto& _str) {
|
const auto read_string = [_flag](const auto& _str) {
|
||||||
return read<T, Ps...>(_str);
|
return read<T, Ps...>(_str, _flag);
|
||||||
};
|
};
|
||||||
return rfl::io::load_string(_fname).and_then(read_string);
|
return rfl::io::load_string(_fname).and_then(read_string);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,8 +31,8 @@ auto read(const InputVarType& _obj) {
|
|||||||
/// Parses an object from JSON using reflection.
|
/// Parses an object from JSON using reflection.
|
||||||
template <class T, class... Ps>
|
template <class T, class... Ps>
|
||||||
Result<internal::wrap_in_rfl_array_t<T>> read(
|
Result<internal::wrap_in_rfl_array_t<T>> read(
|
||||||
std::string_view const _json_str) {
|
std::string_view const _json_str, const yyjson_read_flag _flag = 0) {
|
||||||
yyjson_doc* doc = yyjson_read(_json_str.data(), _json_str.size(), 0);
|
yyjson_doc* doc = yyjson_read(_json_str.data(), _json_str.size(), _flag);
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
return error("Could not parse document");
|
return error("Could not parse document");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user