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..29fa045a 100644 --- a/include/rfl/bson/Reader.hpp +++ b/include/rfl/bson/Reader.hpp @@ -120,9 +120,8 @@ 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..64b24869 100644 --- a/include/rfl/capnproto/Reader.hpp +++ b/include/rfl/capnproto/Reader.hpp @@ -68,9 +68,8 @@ class Reader { if (type != capnp::DynamicValue::DATA) { 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 data = internal::ptr_cast(_var.val_.as()); + return rfl::Bytestring(data, data + 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/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.");