diff --git a/README.md b/README.md index d41b854b..d51ecf9a 100644 --- a/README.md +++ b/README.md @@ -515,7 +515,7 @@ In addition, it supports the following custom containers: - `rfl::Binary`: Used to express numbers in binary format. - `rfl::Box`: Similar to `std::unique_ptr`, but (almost) guaranteed to never be null. -- `rfl::Bytestring`: An alias for `std::basic_string`. Supported by Avro, BSON, Cap'n Proto, CBOR, flexbuffers, msgpack and UBJSON. +- `rfl::Bytestring`: An alias for `std::vector`. Supported by Avro, BSON, Cap'n Proto, CBOR, flexbuffers, msgpack and UBJSON. - `rfl::Generic`: A catch-all type that can represent (almost) anything. - `rfl::Hex`: Used to express numbers in hex format. - `rfl::Literal`: An explicitly enumerated string. diff --git a/docs/bytestring.md b/docs/bytestring.md index 92ad231e..e11e6e54 100644 --- a/docs/bytestring.md +++ b/docs/bytestring.md @@ -5,15 +5,10 @@ ```cpp namespace rfl { -using Bytestring = std::basic_string; +using Bytestring = std::vector; } ``` -For more information on how to handle `std::basic_string` please refer to the -relevant documentation: - -https://en.cppreference.com/w/cpp/string/basic_string - Bytestrings are supported by BSON, CBOR, flexbuffers and msgpack. Textual formats do not support them. diff --git a/include/rfl/Bytestring.hpp b/include/rfl/Bytestring.hpp index 896be499..197531e5 100644 --- a/include/rfl/Bytestring.hpp +++ b/include/rfl/Bytestring.hpp @@ -2,11 +2,11 @@ #define RFL_BYTESTRING_HPP_ #include -#include +#include namespace rfl { -using Bytestring = std::basic_string; +using Bytestring = std::vector; } // namespace rfl diff --git a/include/rfl/avro/Reader.hpp b/include/rfl/avro/Reader.hpp index 3f7fd0be..1902949d 100644 --- a/include/rfl/avro/Reader.hpp +++ b/include/rfl/avro/Reader.hpp @@ -75,7 +75,8 @@ struct Reader { if (err) { return error("Could not cast to bytestring."); } - return rfl::Bytestring(static_cast(ptr), size - 1); + const auto data = internal::ptr_cast(ptr); + return rfl::Bytestring(data, data + size - 1); } else if constexpr (std::is_same, bool>()) { if (type != AVRO_BOOLEAN) { return rfl::error("Could not cast to boolean."); diff --git a/include/rfl/bson/Reader.hpp b/include/rfl/bson/Reader.hpp index 494dfc53..3ec64de0 100644 --- a/include/rfl/bson/Reader.hpp +++ b/include/rfl/bson/Reader.hpp @@ -120,9 +120,9 @@ struct Reader { "The BSON subtype must be a binary in order to read into a " "bytestring."); } - return rfl::Bytestring( - internal::ptr_cast(value.v_binary.data), - value.v_binary.data_len); + const auto data = + internal::ptr_cast(value.v_binary.data); + return rfl::Bytestring(data, data + value.v_binary.data_len); } else if constexpr (std::is_same, bool>()) { if (btype != BSON_TYPE_BOOL) { return error("Could not cast to boolean."); diff --git a/include/rfl/capnproto/Reader.hpp b/include/rfl/capnproto/Reader.hpp index 5009a499..3a115481 100644 --- a/include/rfl/capnproto/Reader.hpp +++ b/include/rfl/capnproto/Reader.hpp @@ -69,8 +69,8 @@ class Reader { return error("Could not cast to bytestring."); } const auto data = _var.val_.as(); - return rfl::Bytestring(internal::ptr_cast(data.begin()), - data.size()); + const auto begin = internal::ptr_cast(data.begin()); + return rfl::Bytestring(begin, begin + data.size()); } else if constexpr (std::is_same, bool>()) { if (type != capnp::DynamicValue::BOOL) { diff --git a/include/rfl/cbor/Reader.hpp b/include/rfl/cbor/Reader.hpp index bb01bf00..59e3d736 100644 --- a/include/rfl/cbor/Reader.hpp +++ b/include/rfl/cbor/Reader.hpp @@ -77,8 +77,8 @@ class Reader { return error("Could not cast to bytestring."); } const auto vec = _var.val_->as>(); - return rfl::Bytestring(internal::ptr_cast(vec.data()), - vec.size()); + const auto data = internal::ptr_cast(vec.data()); + return rfl::Bytestring(data, data + vec.size()); } else if constexpr (std::is_same, bool>()) { if (!_var.val_->is_bool()) { return error("Could not cast to boolean."); diff --git a/include/rfl/flexbuf/Reader.hpp b/include/rfl/flexbuf/Reader.hpp index 0cbe7b0c..b1946ca3 100644 --- a/include/rfl/flexbuf/Reader.hpp +++ b/include/rfl/flexbuf/Reader.hpp @@ -80,8 +80,8 @@ struct Reader { return error("Could not cast to a bytestring."); } const auto blob = _var.AsBlob(); - return rfl::Bytestring(internal::ptr_cast(blob.data()), - blob.size()); + const auto data = internal::ptr_cast(blob.data()); + return rfl::Bytestring(data, data + blob.size()); } else if constexpr (std::is_same, bool>()) { if (!_var.IsBool()) { return error("Could not cast to boolean."); diff --git a/include/rfl/internal/enums/StringConverter.hpp b/include/rfl/internal/enums/StringConverter.hpp index b2f3d1b6..c91f2cad 100644 --- a/include/rfl/internal/enums/StringConverter.hpp +++ b/include/rfl/internal/enums/StringConverter.hpp @@ -36,9 +36,6 @@ class StringConverter { /// Transforms a string to the matching enum. static Result string_to_enum(const std::string& _str) { - static_assert(names_.size != 0, - "No enum could be identified. Please choose enum values " - "between 0 to 127 or for flag enums choose 1,2,4,8,16,..."); if constexpr (is_flag_enum_) { return string_to_flag_enum(_str); } else { diff --git a/include/rfl/msgpack/Reader.hpp b/include/rfl/msgpack/Reader.hpp index ecc6a33f..10f325b6 100644 --- a/include/rfl/msgpack/Reader.hpp +++ b/include/rfl/msgpack/Reader.hpp @@ -70,8 +70,8 @@ struct Reader { return error("Could not cast to a bytestring."); } const auto bin = _var.via.bin; - return rfl::Bytestring(internal::ptr_cast(bin.ptr), - bin.size); + const auto data = internal::ptr_cast(bin.ptr); + return rfl::Bytestring(data, data + bin.size); } else if constexpr (std::is_same, bool>()) { if (type != MSGPACK_OBJECT_BOOLEAN) { return error("Could not cast to boolean."); diff --git a/include/rfl/ubjson/Reader.hpp b/include/rfl/ubjson/Reader.hpp index e245735f..c07cbc9a 100644 --- a/include/rfl/ubjson/Reader.hpp +++ b/include/rfl/ubjson/Reader.hpp @@ -77,8 +77,8 @@ class Reader { return error("Could not cast to bytestring."); } const auto vec = _var.val_->as>(); - return rfl::Bytestring(internal::ptr_cast(vec.data()), - vec.size()); + const auto data = internal::ptr_cast(vec.data()); + return rfl::Bytestring(data, data + vec.size()); } else if constexpr (std::is_same, bool>()) { if (!_var.val_->is_bool()) { return error("Could not cast to boolean.");