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
|
#ifndef RFL_AVRO_PARSER_HPP_
#define RFL_AVRO_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 {
/// AVRO 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<avro::Reader, avro::Writer,
NamedTuple<FieldTypes...>>
struct Parser<avro::Reader, avro::Writer, NamedTuple<FieldTypes...>,
ProcessorsType>
: public NamedTupleParser<
avro::Reader, avro::Writer,
/*_ignore_empty_containers=*/false,
/*_all_required=*/true,
/*_no_field_names=*/ProcessorsType::no_field_names_, ProcessorsType,
FieldTypes...> {};
template <class ProcessorsType, class... Ts>
requires AreReaderAndWriter<avro::Reader, avro::Writer, rfl::Tuple<Ts...>>
struct Parser<avro::Reader, avro::Writer, rfl::Tuple<Ts...>, ProcessorsType>
: public TupleParser<avro::Reader, avro::Writer,
/*_ignore_empty_containers=*/false,
/*_all_required=*/true, ProcessorsType,
rfl::Tuple<Ts...>> {};
template <class ProcessorsType, class... Ts>
requires AreReaderAndWriter<avro::Reader, avro::Writer, std::tuple<Ts...>>
struct Parser<avro::Reader, avro::Writer, std::tuple<Ts...>, ProcessorsType>
: public TupleParser<avro::Reader, avro::Writer,
/*_ignore_empty_containers=*/false,
/*_all_required=*/true, ProcessorsType,
std::tuple<Ts...>> {};
template <class ProcessorsType>
requires AreReaderAndWriter<avro::Reader, avro::Writer, Generic>
struct Parser<avro::Reader, avro::Writer, Generic, ProcessorsType> {
template <class T>
static Result<Generic> read(const avro::Reader&, const T&) noexcept {
static_assert(always_false_v<T>, "Generics are unsupported in Avro.");
return error("Unsupported");
}
template <class P>
static void write(const avro::Writer&, const Generic&, const P&) noexcept {
static_assert(always_false_v<P>, "Generics are unsupported in Avro.");
}
template <class T>
static schema::Type to_schema(T*) {
static_assert(always_false_v<T>, "Generics are unsupported in Avro.");
return schema::Type{};
}
};
template <class T, bool _skip_serialization, bool _skip_deserialization,
class ProcessorsType>
requires AreReaderAndWriter<
avro::Reader, avro::Writer,
internal::Skip<T, _skip_serialization, _skip_deserialization>>
struct Parser<avro::Reader, avro::Writer,
internal::Skip<T, _skip_serialization, _skip_deserialization>,
ProcessorsType> {
using R = avro::Reader;
using W = avro::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 Avro.");
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 Avro.");
}
template <class U>
static schema::Type to_schema(U* _definitions) {
static_assert(always_false_v<U>, "rfl::Skip is unsupported in Avro.");
return schema::Type{};
}
};
} // namespace parsing
} // namespace rfl
namespace rfl {
namespace avro {
template <class T, class ProcessorsType>
using Parser = parsing::Parser<Reader, Writer, T, ProcessorsType>;
}
} // namespace rfl
#endif
|