mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-12-03 16:56:17 +08:00
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
#include "../Result.hpp"
|
#include "../Result.hpp"
|
||||||
#include "../always_false.hpp"
|
#include "../always_false.hpp"
|
||||||
#include "../internal/Skip.hpp"
|
#include "../internal/Skip.hpp"
|
||||||
|
#include "Parent.hpp"
|
||||||
#include "Parser_base.hpp"
|
#include "Parser_base.hpp"
|
||||||
#include "schema/Type.hpp"
|
#include "schema/Type.hpp"
|
||||||
|
|
||||||
@@ -15,12 +16,13 @@ namespace parsing {
|
|||||||
|
|
||||||
template <class R, class W, class T, bool _skip_serialization,
|
template <class R, class W, class T, bool _skip_serialization,
|
||||||
bool _skip_deserialization, class ProcessorsType>
|
bool _skip_deserialization, class ProcessorsType>
|
||||||
requires AreReaderAndWriter<
|
requires AreReaderAndWriter<
|
||||||
R, W, internal::Skip<T, _skip_serialization, _skip_deserialization>>
|
R, W, internal::Skip<T, _skip_serialization, _skip_deserialization>>
|
||||||
struct Parser<R, W,
|
struct Parser<R, W,
|
||||||
internal::Skip<T, _skip_serialization, _skip_deserialization>,
|
internal::Skip<T, _skip_serialization, _skip_deserialization>,
|
||||||
ProcessorsType> {
|
ProcessorsType> {
|
||||||
using InputVarType = typename R::InputVarType;
|
using InputVarType = typename R::InputVarType;
|
||||||
|
using ParentType = Parent<W>;
|
||||||
|
|
||||||
static Result<internal::Skip<T, _skip_serialization, _skip_deserialization>>
|
static Result<internal::Skip<T, _skip_serialization, _skip_deserialization>>
|
||||||
read(const R& _r, const InputVarType& _var) noexcept {
|
read(const R& _r, const InputVarType& _var) noexcept {
|
||||||
@@ -44,10 +46,7 @@ struct Parser<R, W,
|
|||||||
_skip_deserialization>& _skip,
|
_skip_deserialization>& _skip,
|
||||||
const P& _parent) noexcept {
|
const P& _parent) noexcept {
|
||||||
if constexpr (_skip_serialization) {
|
if constexpr (_skip_serialization) {
|
||||||
using ReflectionType = std::remove_cvref_t<typename internal::Skip<
|
ParentType::add_null(_w, _parent);
|
||||||
T, _skip_serialization, _skip_deserialization>::ReflectionType>;
|
|
||||||
Parser<R, W, ReflectionType, ProcessorsType>::write(_w, ReflectionType(),
|
|
||||||
_parent);
|
|
||||||
} else {
|
} else {
|
||||||
Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::write(
|
Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::write(
|
||||||
_w, _skip.value(), _parent);
|
_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