mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-02 16:16:19 +08:00
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "../Result.hpp"
|
||||
#include "../always_false.hpp"
|
||||
#include "../internal/Skip.hpp"
|
||||
#include "Parent.hpp"
|
||||
#include "Parser_base.hpp"
|
||||
#include "schema/Type.hpp"
|
||||
|
||||
@@ -15,12 +16,13 @@ namespace parsing {
|
||||
|
||||
template <class R, class W, class T, bool _skip_serialization,
|
||||
bool _skip_deserialization, class ProcessorsType>
|
||||
requires AreReaderAndWriter<
|
||||
R, W, internal::Skip<T, _skip_serialization, _skip_deserialization>>
|
||||
requires AreReaderAndWriter<
|
||||
R, W, internal::Skip<T, _skip_serialization, _skip_deserialization>>
|
||||
struct Parser<R, W,
|
||||
internal::Skip<T, _skip_serialization, _skip_deserialization>,
|
||||
ProcessorsType> {
|
||||
using InputVarType = typename R::InputVarType;
|
||||
using ParentType = Parent<W>;
|
||||
|
||||
static Result<internal::Skip<T, _skip_serialization, _skip_deserialization>>
|
||||
read(const R& _r, const InputVarType& _var) noexcept {
|
||||
@@ -44,10 +46,7 @@ struct Parser<R, W,
|
||||
_skip_deserialization>& _skip,
|
||||
const P& _parent) noexcept {
|
||||
if constexpr (_skip_serialization) {
|
||||
using ReflectionType = std::remove_cvref_t<typename internal::Skip<
|
||||
T, _skip_serialization, _skip_deserialization>::ReflectionType>;
|
||||
Parser<R, W, ReflectionType, ProcessorsType>::write(_w, ReflectionType(),
|
||||
_parent);
|
||||
ParentType::add_null(_w, _parent);
|
||||
} else {
|
||||
Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::write(
|
||||
_w, _skip.value(), _parent);
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
namespace test_skip2 {
|
||||
|
||||
using Age = rfl::Validator<unsigned int, rfl::Minimum<0>, rfl::Maximum<130>>;
|
||||
|
||||
struct Person {
|
||||
rfl::Rename<"firstName", std::string> first_name;
|
||||
rfl::Rename<"lastName", std::string> last_name;
|
||||
rfl::Skip<rfl::Bytestring> town; // Is unsupported by the JSON format
|
||||
Age age;
|
||||
};
|
||||
|
||||
TEST(json, test_skip2) {
|
||||
const auto homer =
|
||||
Person{.first_name = "Homer", .last_name = "Simpson", .age = 45};
|
||||
|
||||
write_and_read(homer,
|
||||
R"({"firstName":"Homer","lastName":"Simpson","age":45})");
|
||||
}
|
||||
} // namespace test_skip2
|
||||
@@ -0,0 +1,28 @@
|
||||
#include <iostream>
|
||||
#include <rfl.hpp>
|
||||
#include <rfl/json.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "write_and_read.hpp"
|
||||
|
||||
namespace test_skip {
|
||||
|
||||
using Age = rfl::Validator<unsigned int, rfl::Minimum<0>, rfl::Maximum<130>>;
|
||||
|
||||
struct Person {
|
||||
rfl::Rename<"firstName", std::string> first_name;
|
||||
rfl::Rename<"lastName", std::string> last_name;
|
||||
rfl::Skip<std::string> town;
|
||||
Age age;
|
||||
};
|
||||
|
||||
TEST(yaml, test_skip) {
|
||||
const auto homer = Person{.first_name = "Homer",
|
||||
.last_name = "Simpson",
|
||||
.town = "Springfield",
|
||||
.age = 45};
|
||||
|
||||
write_and_read(homer);
|
||||
}
|
||||
} // namespace test_skip
|
||||
Reference in New Issue
Block a user