1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
#ifndef RFL_CAPNPROTO_PARSER_HPP_
#define RFL_CAPNPROTO_PARSER_HPP_
#include "../Generic.hpp"
#include "../Tuple.hpp"
#include "../always_false.hpp"
#include "../parsing/Parser.hpp"
#include "Reader.hpp"
#include "Writer.hpp"
namespace rfl {
namespace parsing {
/// Cap'n proto requires us to explicitly set all fields. Because
/// of that, we require all of the fields and then set them to nullptr, if
/// necessary.
template <class ProcessorsType, class... FieldTypes>
requires AreReaderAndWriter<capnproto::Reader, capnproto::Writer,
NamedTuple<FieldTypes...>>
struct Parser<capnproto::Reader, capnproto::Writer, NamedTuple<FieldTypes...>,
ProcessorsType>
: public NamedTupleParser<
capnproto::Reader, capnproto::Writer,
/*_ignore_empty_containers=*/false,
/*_all_required=*/true,
/*_no_field_names=*/ProcessorsType::no_field_names_, ProcessorsType,
FieldTypes...> {};
template <class ProcessorsType, class... Ts>
requires AreReaderAndWriter<capnproto::Reader, capnproto::Writer,
rfl::Tuple<Ts...>>
struct Parser<capnproto::Reader, capnproto::Writer, rfl::Tuple<Ts...>,
ProcessorsType>
: public TupleParser<capnproto::Reader, capnproto::Writer,
/*_ignore_empty_containers=*/false,
/*_all_required=*/true, ProcessorsType,
rfl::Tuple<Ts...>> {};
template <class ProcessorsType, class... Ts>
requires AreReaderAndWriter<capnproto::Reader, capnproto::Writer,
std::tuple<Ts...>>
struct Parser<capnproto::Reader, capnproto::Writer, std::tuple<Ts...>,
ProcessorsType>
: public TupleParser<capnproto::Reader, capnproto::Writer,
/*_ignore_empty_containers=*/false,
/*_all_required=*/true, ProcessorsType,
std::tuple<Ts...>> {};
template <class ProcessorsType>
requires AreReaderAndWriter<capnproto::Reader, capnproto::Writer, Generic>
struct Parser<capnproto::Reader, capnproto::Writer, Generic, ProcessorsType> {
template <class T>
static Result<Generic> read(const capnproto::Reader&, const T&) noexcept {
static_assert(always_false_v<T>,
"Generics are unsupported in Cap'n Proto.");
return error("Unsupported");
}
template <class P>
static void write(const capnproto::Writer&, const Generic&,
const P&) noexcept {
static_assert(always_false_v<P>,
"Generics are unsupported in Cap'n Proto.");
}
template <class T>
static schema::Type to_schema(T*) {
static_assert(always_false_v<T>,
"Generics are unsupported in Cap'n Proto.");
return schema::Type{};
}
};
template <class T, bool _skip_serialization, bool _skip_deserialization,
class ProcessorsType>
requires AreReaderAndWriter<
capnproto::Reader, capnproto::Writer,
internal::Skip<T, _skip_serialization, _skip_deserialization>>
struct Parser<capnproto::Reader, capnproto::Writer,
internal::Skip<T, _skip_serialization, _skip_deserialization>,
ProcessorsType> {
using R = capnproto::Reader;
using W = capnproto::Writer;
template <class U>
static Result<internal::Skip<T, _skip_serialization, _skip_deserialization>>
read(const R&, const U&) noexcept {
static_assert(always_false_v<T>,
"rfl::Skip is unsupported in Cap'n Proto.");
return error("Unsupported");
}
template <class P>
static void write(const W& _w,
const internal::Skip<T, _skip_serialization,
_skip_deserialization>& _skip,
const P& _parent) noexcept {
static_assert(always_false_v<P>,
"rfl::Skip is unsupported in Cap'n Proto.");
}
template <class U>
static schema::Type to_schema(U* _definitions) {
static_assert(always_false_v<U>,
"rfl::Skip is unsupported in Cap'n Proto.");
return schema::Type{};
}
};
} // namespace parsing
} // namespace rfl
namespace rfl {
namespace capnproto {
template <class T, class ProcessorsType>
using Parser = parsing::Parser<Reader, Writer, T, ProcessorsType>;
}
} // namespace rfl
#endif
|