Skip to content

Commit a817d40

Browse files
committed
include parser specializations for vectorstring
1 parent 2a99913 commit a817d40

6 files changed

Lines changed: 57 additions & 1 deletion

File tree

include/rfl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include "rfl/UnderlyingEnums.hpp"
4646
#include "rfl/Validator.hpp"
4747
#include "rfl/Variant.hpp"
48+
#include "rfl/Vectorstring.hpp"
4849
#include "rfl/always_false.hpp"
4950
#include "rfl/apply.hpp"
5051
#include "rfl/as.hpp"

include/rfl/Bytestring.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace rfl {
88

99
using Bytestring = std::vector<std::byte>;
10-
using Vectorstring = std::vector<char>;
1110

1211
} // namespace rfl
1312

include/rfl/Vectorstring.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef RFL_VECTORSTRING_HPP_
2+
#define RFL_VECTORSTRING_HPP_
3+
4+
#include <cstddef>
5+
#include <vector>
6+
7+
namespace rfl {
8+
9+
using Vectorstring = std::vector<char>;
10+
11+
} // namespace rfl
12+
13+
#endif
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef RFL_PARSING_PARSER_VECTORSRING_HPP_
2+
#define RFL_PARSING_PARSER_VECTORSRING_HPP_
3+
4+
#include <map>
5+
6+
#include "../Vectorstring.hpp"
7+
#include "../Result.hpp"
8+
#include "Parser_base.hpp"
9+
#include "schema/Type.hpp"
10+
11+
namespace rfl::parsing {
12+
13+
template <class R, class W, class ProcessorsType>
14+
requires AreReaderAndWriter<R, W, Vectorstring>
15+
struct Parser<R, W, Vectorstring, ProcessorsType> {
16+
using InputVarType = typename R::InputVarType;
17+
using ParentType = Parent<W>;
18+
19+
static Result<Vectorstring> read(const R& _r,
20+
const InputVarType& _var) noexcept {
21+
return _r.template to_basic_type<Vectorstring>(_var);
22+
}
23+
24+
template <class P>
25+
static void write(const W& _w, const Vectorstring& _b,
26+
const P& _parent) noexcept {
27+
ParentType::add_value(_w, _b, _parent);
28+
}
29+
30+
static schema::Type to_schema(
31+
std::map<std::string, schema::Type>* _definitions) {
32+
return schema::Type{schema::Type::Vectorstring{}};
33+
}
34+
};
35+
36+
} // namespace rfl::parsing
37+
38+
#endif

include/rfl/parsing/VectorParser.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "../Bytestring.hpp"
1111
#include "../Result.hpp"
12+
#include "../Vectorstring.hpp"
1213
#include "../always_false.hpp"
1314
#include "MapParser.hpp"
1415
#include "Parent.hpp"
@@ -40,6 +41,8 @@ struct VectorParser {
4041

4142
static_assert(!std::is_same_v<std::remove_cvref_t<VecType>, Bytestring>,
4243
"Cannot be a bytestring.");
44+
static_assert(!std::is_same_v<std::remove_cvref_t<VecType>, Vectorstring>,
45+
"Cannot be a vectorstring.");
4346

4447
static Result<VecType> read(const R& _r, const InputVarType& _var) noexcept {
4548
if constexpr (treat_as_map()) {

include/rfl/parsing/schema/Type.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ struct Type {
1818

1919
struct Bytestring {};
2020

21+
struct Vectorstring {};
22+
2123
struct Int32 {};
2224

2325
struct Int64 {};

0 commit comments

Comments
 (0)