Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/bytestring.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ using Bytestring = std::vector<std::byte>;
}
```

Bytestrings are supported by BSON, CBOR, flexbuffers and msgpack. Textual formats
do not support them.
Bytestrings are supported by binary formats such as BSON, CBOR, flexbuffers and msgpack.
Textual formats do not support them.
9 changes: 2 additions & 7 deletions include/rfl/Bytestring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
#include <vector>

namespace rfl {
// custom type to avoid serializing this as a vector of enums
// in other means this is the same as
// using Bytestring = std::vector<std::byte>;
class Bytestring : public std::vector<std::byte> {
public:
using std::vector<std::byte>::vector;
};

using Bytestring = std::vector<std::byte>;

} // namespace rfl

Expand Down
1 change: 1 addition & 0 deletions include/rfl/parsing/Parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Parser_array.hpp"
#include "Parser_base.hpp"
#include "Parser_box.hpp"
#include "Parser_bytestring.hpp"
#include "Parser_c_array.hpp"
#include "Parser_default.hpp"
#include "Parser_duration.hpp"
Expand Down
38 changes: 38 additions & 0 deletions include/rfl/parsing/Parser_bytestring.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#ifndef RFL_PARSING_PARSER_BYTESTRING_HPP_
#define RFL_PARSING_PARSER_BYTESTRING_HPP_

#include <map>

#include "../Bytestring.hpp"
#include "../Result.hpp"
#include "Parser_base.hpp"
#include "schema/Type.hpp"

namespace rfl::parsing {

template <class R, class W, class ProcessorsType>
requires AreReaderAndWriter<R, W, Bytestring>
struct Parser<R, W, Bytestring, ProcessorsType> {
using InputVarType = typename R::InputVarType;
using ParentType = Parent<W>;

static Result<Bytestring> read(const R& _r,
const InputVarType& _var) noexcept {
return _r.template to_basic_type<Bytestring>(_var);
}

template <class P>
static void write(const W& _w, const Bytestring& _b,
const P& _parent) noexcept {
ParentType::add_value(_w, _b, _parent);
}

static schema::Type to_schema(
std::map<std::string, schema::Type>* _definitions) {
return schema::Type{schema::Type::Bytestring{}};
}
};

} // namespace rfl::parsing

#endif
4 changes: 0 additions & 4 deletions include/rfl/parsing/Parser_default.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <stdexcept>
#include <type_traits>

#include "../Bytestring.hpp"
#include "../Result.hpp"
#include "../always_false.hpp"
#include "../from_named_tuple.hpp"
Expand Down Expand Up @@ -152,9 +151,6 @@ struct Parser {
if constexpr (std::is_same<U, bool>()) {
return Type{Type::Boolean{}};

} else if constexpr (std::is_same<U, rfl::Bytestring>()) {
return Type{Type::Bytestring{}};

} else if constexpr (std::is_same<U, std::int32_t>()) {
return Type{Type::Int32{}};

Expand Down
4 changes: 4 additions & 0 deletions include/rfl/parsing/VectorParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include <type_traits>

#include "../Bytestring.hpp"
#include "../Result.hpp"
#include "../always_false.hpp"
#include "MapParser.hpp"
Expand Down Expand Up @@ -37,6 +38,9 @@ struct VectorParser {

using T = typename VecType::value_type;

static_assert(!std::is_same_v<std::remove_cvref_t<VecType>, Bytestring>,
"Cannot be a bytestring.");

static Result<VecType> read(const R& _r, const InputVarType& _var) noexcept {
if constexpr (treat_as_map()) {
return MapParser<R, W, VecType, ProcessorsType>::read(_r, _var);
Expand Down
Loading