Skip to content

Commit 4e4a16d

Browse files
Started fixing the Avro error
1 parent 72a7214 commit 4e4a16d

5 files changed

Lines changed: 215 additions & 101 deletions

File tree

include/rfl/avro/Parser.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#include "../Generic.hpp"
55
#include "../Tuple.hpp"
66
#include "../always_false.hpp"
7-
//#include "../parsing/Parser.hpp"
7+
// #include "../parsing/Parser.hpp"
88
#include "Reader.hpp"
99
#include "Writer.hpp"
1010

@@ -46,13 +46,13 @@ template <class ProcessorsType>
4646
requires AreReaderAndWriter<avro::Reader, avro::Writer, Generic>
4747
struct Parser<avro::Reader, avro::Writer, Generic, ProcessorsType> {
4848
template <class T>
49-
static Result<Generic> read(const avro::Reader&, const T&) noexcept {
49+
static Result<Generic> read(const avro::Reader&, const T&) {
5050
static_assert(always_false_v<T>, "Generics are unsupported in Avro.");
5151
return error("Unsupported");
5252
}
5353

5454
template <class P>
55-
static void write(const avro::Writer&, const Generic&, const P&) noexcept {
55+
static void write(const avro::Writer&, const Generic&, const P&) {
5656
static_assert(always_false_v<P>, "Generics are unsupported in Avro.");
5757
}
5858

@@ -76,7 +76,7 @@ struct Parser<avro::Reader, avro::Writer,
7676

7777
template <class U>
7878
static Result<internal::Skip<T, _skip_serialization, _skip_deserialization>>
79-
read(const R&, const U&) noexcept {
79+
read(const R&, const U&) {
8080
static_assert(always_false_v<T>, "rfl::Skip is unsupported in Avro.");
8181
return Error("Unsupported");
8282
}
@@ -85,7 +85,7 @@ struct Parser<avro::Reader, avro::Writer,
8585
static void write(const W& /*_w*/,
8686
const internal::Skip<T, _skip_serialization,
8787
_skip_deserialization>& /*_skip*/,
88-
const P& /*_parent*/) noexcept {
88+
const P& /*_parent*/) {
8989
static_assert(always_false_v<P>, "rfl::Skip is unsupported in Avro.");
9090
}
9191

include/rfl/avro/Writer.hpp

Lines changed: 57 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#ifndef RFL_AVRO_WRITER_HPP_
22
#define RFL_AVRO_WRITER_HPP_
33

4+
#include <avro.h>
5+
46
#include <cstdint>
57
#include <string>
68
#include <string_view>
79
#include <type_traits>
810

9-
#include <avro.h>
10-
11-
//#include "../Box.hpp"
11+
// #include "../Box.hpp"
1212
#include "../Bytestring.hpp"
13-
//#include "../Ref.hpp"
14-
//#include "../Result.hpp"
13+
// #include "../Ref.hpp"
14+
// #include "../Result.hpp"
1515
#include "../Vectorstring.hpp"
1616
#include "../always_false.hpp"
17-
#include "../internal/is_literal.hpp"
1817
#include "../common.hpp"
18+
#include "../internal/is_literal.hpp"
1919

2020
namespace rfl::avro {
2121

@@ -51,15 +51,15 @@ class RFL_API Writer {
5151

5252
~Writer();
5353

54-
OutputArrayType array_as_root(const size_t _size) const noexcept;
54+
OutputArrayType array_as_root(const size_t _size) const;
5555

56-
OutputMapType map_as_root(const size_t _size) const noexcept;
56+
OutputMapType map_as_root(const size_t _size) const;
5757

58-
OutputObjectType object_as_root(const size_t _size) const noexcept;
58+
OutputObjectType object_as_root(const size_t _size) const;
5959

6060
OutputVarType null_as_root() const;
6161

62-
OutputUnionType union_as_root() const noexcept;
62+
OutputUnionType union_as_root() const;
6363

6464
template <class T>
6565
OutputVarType value_as_root(const T& _var) const {
@@ -102,9 +102,9 @@ class RFL_API Writer {
102102
const size_t _size,
103103
OutputMapType* _parent) const;
104104

105-
OutputObjectType add_object_to_object(
106-
const std::string_view& _name, const size_t _size,
107-
OutputObjectType* _parent) const;
105+
OutputObjectType add_object_to_object(const std::string_view& _name,
106+
const size_t _size,
107+
OutputObjectType* _parent) const;
108108

109109
OutputObjectType add_object_to_union(const size_t _index, const size_t _size,
110110
OutputUnionType* _parent) const;
@@ -137,7 +137,9 @@ class RFL_API Writer {
137137
avro_value_t new_value;
138138
int result = avro_value_append(&_parent->val_, &new_value, nullptr);
139139
if (result != 0) {
140-
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
140+
throw std::runtime_error(std::string(__FUNCTION__) + " error(" +
141+
std::to_string(result) +
142+
"): " + avro_strerror());
141143
}
142144
set_value(_var, &new_value);
143145
return OutputVarType{new_value};
@@ -147,9 +149,12 @@ class RFL_API Writer {
147149
OutputVarType add_value_to_map(const std::string_view& _name, const T& _var,
148150
OutputMapType* _parent) const {
149151
avro_value_t new_value;
150-
int result = avro_value_add(&_parent->val_, _name.data(), &new_value, nullptr, nullptr);
152+
int result = avro_value_add(&_parent->val_, _name.data(), &new_value,
153+
nullptr, nullptr);
151154
if (result != 0) {
152-
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
155+
throw std::runtime_error(std::string(__FUNCTION__) + " error(" +
156+
std::to_string(result) +
157+
"): " + avro_strerror());
153158
}
154159
set_value(_var, &new_value);
155160
return OutputVarType{new_value};
@@ -160,9 +165,12 @@ class RFL_API Writer {
160165
const T& _var,
161166
OutputObjectType* _parent) const {
162167
avro_value_t new_value;
163-
int result = avro_value_get_by_name(&_parent->val_, _name.data(), &new_value, nullptr);
168+
int result = avro_value_get_by_name(&_parent->val_, _name.data(),
169+
&new_value, nullptr);
164170
if (result != 0) {
165-
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
171+
throw std::runtime_error(std::string(__FUNCTION__) + " error(" +
172+
std::to_string(result) +
173+
"): " + avro_strerror());
166174
}
167175
set_value(_var, &new_value);
168176
return OutputVarType{new_value};
@@ -175,9 +183,12 @@ class RFL_API Writer {
175183
throw std::runtime_error(std::string(__FUNCTION__) + " index error");
176184
}
177185
avro_value_t new_value;
178-
int result = avro_value_set_branch(&_parent->val_, static_cast<int>(_index), &new_value);
186+
int result = avro_value_set_branch(&_parent->val_, static_cast<int>(_index),
187+
&new_value);
179188
if (result != 0) {
180-
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
189+
throw std::runtime_error(std::string(__FUNCTION__) + " error(" +
190+
std::to_string(result) +
191+
"): " + avro_strerror());
181192
}
182193
set_value(_var, &new_value);
183194
return OutputVarType{new_value};
@@ -193,9 +204,12 @@ class RFL_API Writer {
193204
template <class T>
194205
void set_value(const T& _var, avro_value_t* _val) const {
195206
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
196-
int result = avro_value_set_string_len(_val, _var.c_str(), _var.size() + 1);
207+
int result =
208+
avro_value_set_string_len(_val, _var.c_str(), _var.size() + 1);
197209
if (result != 0) {
198-
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
210+
throw std::runtime_error(std::string(__FUNCTION__) + " error(" +
211+
std::to_string(result) +
212+
"): " + avro_strerror());
199213
}
200214
} else if constexpr (std::is_same<std::remove_cvref_t<T>,
201215
rfl::Bytestring>() ||
@@ -207,35 +221,44 @@ class RFL_API Writer {
207221
}
208222
int result = avro_value_set_bytes(_val, var.data(), var.size());
209223
if (result != 0) {
210-
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
224+
throw std::runtime_error(std::string(__FUNCTION__) + " error(" +
225+
std::to_string(result) +
226+
"): " + avro_strerror());
211227
}
212228
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
213229
int result = avro_value_set_boolean(_val, _var);
214230
if (result != 0) {
215-
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
231+
throw std::runtime_error(std::string(__FUNCTION__) + " error(" +
232+
std::to_string(result) +
233+
"): " + avro_strerror());
216234
}
217235
} else if constexpr (std::is_floating_point<std::remove_cvref_t<T>>()) {
218-
/*int result = avro_value_set_double(_val, static_cast<double>(_var));
236+
int result = avro_value_set_double(_val, static_cast<double>(_var));
219237
if (result != 0) {
220-
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
221-
}*/
222-
avro_value_set_double(_val, static_cast<double>(_var));
238+
throw std::runtime_error(std::string(__FUNCTION__) + " error(" +
239+
std::to_string(result) +
240+
"): " + avro_strerror());
241+
}
223242
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
224-
/*int result = avro_value_set_long(_val, static_cast<std::int64_t>(_var));
243+
int result = avro_value_set_long(_val, static_cast<std::int64_t>(_var));
225244
if (result != 0) {
226-
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
227-
}*/
228-
avro_value_set_long(_val, static_cast<std::int64_t>(_var));
245+
throw std::runtime_error(std::string(__FUNCTION__) + " error(" +
246+
std::to_string(result) +
247+
"): " + avro_strerror());
248+
}
229249
} else if constexpr (internal::is_literal_v<T>) {
230250
int result = avro_value_set_enum(_val, static_cast<int>(_var.value()));
231251
if (result != 0) {
232-
throw std::runtime_error(std::string(__FUNCTION__) + " error("+ std::to_string(result)+"): " + avro_strerror());
252+
throw std::runtime_error(std::string(__FUNCTION__) + " error(" +
253+
std::to_string(result) +
254+
"): " + avro_strerror());
233255
}
234256
} else if constexpr (internal::is_validator_v<T>) {
235257
using ValueType = std::remove_cvref_t<typename T::ReflectionType>;
236258
const auto val = _var.value();
237259
set_value<ValueType>(val, _val);
238-
} else if constexpr (std::is_same<std::remove_cvref_t<T>, rfl::Timestamp<"%Y-%m-%d">>()) {
260+
} else if constexpr (std::is_same<std::remove_cvref_t<T>,
261+
rfl::Timestamp<"%Y-%m-%d">>()) {
239262
const auto str = _var.to_string();
240263
set_value<std::string>(str, _val);
241264
} else if constexpr (std::is_same<std::remove_cvref_t<T>, rfl::Email>()) {

0 commit comments

Comments
 (0)