Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions include/rfl/Bytestring.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace rfl {

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

} // namespace rfl

Expand Down
14 changes: 14 additions & 0 deletions include/rfl/bson/Reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,20 @@ struct Reader {
internal::ptr_cast<const std::byte*>(value.v_binary.data);
return rfl::Bytestring(data, data + value.v_binary.data_len);

} else if constexpr (std::is_same<std::remove_cvref_t<T>,
rfl::Vectorstring>()) {
if (btype != BSON_TYPE_BINARY) {
return error("Could not cast to vectorstring.");
}
if (value.v_binary.subtype != BSON_SUBTYPE_BINARY) {
return error(
"The BSON subtype must be a binary in order to read into a "
"vectorstring.");
}
const auto data =
internal::ptr_cast<const char*>(value.v_binary.data);
return rfl::Vectorstring(data, data + value.v_binary.data_len);

} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
if (btype != BSON_TYPE_BOOL) {
return error("Could not cast to boolean.");
Expand Down
4 changes: 3 additions & 1 deletion include/rfl/bson/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ class Writer {
bson_array_builder_append_utf8(_parent->val_, _var.c_str(),
static_cast<int>(_var.size()));
} else if constexpr (std::is_same<std::remove_cvref_t<T>,
rfl::Bytestring>()) {
rfl::Bytestring>() ||
std::is_same<std::remove_cvref_t<T>,
rfl::Vectorstring>()) {
Comment thread
liuzicheng1987 marked this conversation as resolved.
bson_array_builder_append_binary(
_parent->val_, BSON_SUBTYPE_BINARY,
internal::ptr_cast<const uint8_t*>(_var.data()),
Expand Down
9 changes: 9 additions & 0 deletions include/rfl/cbor/Reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@
const auto data = internal::ptr_cast<const std::byte*>(vec.data());
return rfl::Bytestring(data, data + vec.size());

} else if constexpr (std::is_same<std::remove_cvref_t<T>,
rfl::Vectorstring()) {

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-latest)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-latest)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-latest)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-latest)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-latest)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-latest)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-latest)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-latest)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-latest)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-13)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-13)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-13)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-16)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-16)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-16)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-16)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-16)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-16)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-16)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-16)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-16)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-18)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-18)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-18)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-18)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-18)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-18)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-18)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-18)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-18)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-17)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-17)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-17)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-17)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-17)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-17)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-17)

expected unqualified-id

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-17)

type name requires a specifier or qualifier

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-17)

expected '>'

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-13)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-13)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-13)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-13)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-13)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-13)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-13)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-13)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-13)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-13)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-13)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-13)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-11)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-11)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-11)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-11)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-11)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-11)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-11)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-11)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-12)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-12)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-12)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-12)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-12)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-12)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-12)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-12)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-14)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-14)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-14)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-14)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-14)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-14)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-14)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-14)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-14)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-14)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-14)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-14)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-14)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-14)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-14)

expected unqualified-id before ‘)’ token

Check failure on line 85 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-14)

type/value mismatch at argument 2 in template parameter list for ‘template<class, class> struct std::is_same’
if (!_var.val_->is_byte_string()) {
return error("Could not cast to vectorstring.");
}
const auto vec = _var.val_->as<std::vector<uint8_t>>();
const auto data = internal::ptr_cast<const char*>(vec.data());
return rfl::Vectorstring(data, data + vec.size());

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-latest)

no viable conversion from returned value of type 'rfl::Vectorstring' (aka 'vector<char>') to function return type 'rfl::Result<unsigned int>'

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / macos-clang (macos-13)

no viable conversion from returned value of type 'rfl::Vectorstring' (aka 'vector<char>') to function return type 'rfl::Result<unsigned int>'

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-16)

no viable conversion from returned value of type 'rfl::Vectorstring' (aka 'vector<char>') to function return type 'rfl::Result<unsigned int>'

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-18)

no viable conversion from returned value of type 'rfl::Vectorstring' (aka 'vector<char>') to function return type 'rfl::Result<unsigned int>'

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-llvm-17)

no viable conversion from returned value of type 'rfl::Vectorstring' (aka 'vector<char>') to function return type 'rfl::Result<unsigned int>'

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-13)

could not convert ‘std::vector<char>(((const char*)data), (((const char*)data) + ((sizetype)vec.std::vector<unsigned char>::size())), std::allocator<char>())’ from ‘rfl::Vectorstring’ {aka ‘std::vector<char>’} to ‘rfl::Result<unsigned int>’

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-13)

could not convert ‘std::vector<char>(((const char*)data), (((const char*)data) + ((sizetype)vec.std::vector<unsigned char>::size())), std::allocator<char>())’ from ‘rfl::Vectorstring’ {aka ‘std::vector<char>’} to ‘rfl::Result<double>’

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-13)

could not convert ‘std::vector<char>(((const char*)data), (((const char*)data) + ((sizetype)vec.std::vector<unsigned char>::size())), std::allocator<char>())’ from ‘rfl::Vectorstring’ {aka ‘std::vector<char>’} to ‘rfl::Result<unsigned int>’

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-11)

could not convert ‘std::vector<char>(((const char*)data), (((const char*)data) + ((sizetype)vec.std::vector<unsigned char>::size())), std::allocator<char>())’ from ‘rfl::Vectorstring’ {aka ‘std::vector<char>’} to ‘rfl::Result<double>’

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-11)

could not convert ‘std::vector<char>(((const char*)data), (((const char*)data) + ((sizetype)vec.std::vector<unsigned char>::size())), std::allocator<char>())’ from ‘rfl::Vectorstring’ {aka ‘std::vector<char>’} to ‘rfl::Result<unsigned int>’

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-12)

could not convert ‘std::vector<char>(((const char*)data), (((const char*)data) + ((sizetype)vec.std::vector<unsigned char>::size())), std::allocator<char>())’ from ‘rfl::Vectorstring’ {aka ‘std::vector<char>’} to ‘rfl::Result<double>’

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-12)

could not convert ‘std::vector<char>(((const char*)data), (((const char*)data) + ((sizetype)vec.std::vector<unsigned char>::size())), std::allocator<char>())’ from ‘rfl::Vectorstring’ {aka ‘std::vector<char>’} to ‘rfl::Result<unsigned int>’

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-14)

could not convert ‘std::vector<char>(((const char*)data), (((const char*)data) + ((sizetype)vec.std::vector<unsigned char>::size())), std::allocator<char>())’ from ‘rfl::Vectorstring’ {aka ‘std::vector<char>’} to ‘rfl::Result<double>’

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++23-gcc-14)

could not convert ‘std::vector<char>(((const char*)data), (((const char*)data) + ((sizetype)vec.std::vector<unsigned char>::size())), std::allocator<char>())’ from ‘rfl::Vectorstring’ {aka ‘std::vector<char>’} to ‘rfl::Result<unsigned int>’

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-14)

could not convert ‘std::vector<char>(((const char*)data), (((const char*)data) + ((sizetype)vec.std::vector<unsigned char>::size())), std::allocator<char>())’ from ‘rfl::Vectorstring’ {aka ‘std::vector<char>’} to ‘rfl::Result<double>’

Check failure on line 91 in include/rfl/cbor/Reader.hpp

View workflow job for this annotation

GitHub Actions / (C++20-gcc-14)

could not convert ‘std::vector<char>(((const char*)data), (((const char*)data) + ((sizetype)vec.std::vector<unsigned char>::size())), std::allocator<char>())’ from ‘rfl::Vectorstring’ {aka ‘std::vector<char>’} to ‘rfl::Result<unsigned int>’

} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
if (!_var.val_->is_bool()) {
return error("Could not cast to boolean.");
Expand Down
4 changes: 3 additions & 1 deletion include/rfl/cbor/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ class Writer {
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
encoder_->string_value(_var);
} else if constexpr (std::is_same<std::remove_cvref_t<T>,
rfl::Bytestring>()) {
rfl::Bytestring>() ||
std::is_same<std::remove_cvref_t<T>,
rfl::Vectorstring>()) {
encoder_->byte_string_value(_var);
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
encoder_->bool_value(_var);
Expand Down
9 changes: 9 additions & 0 deletions include/rfl/msgpack/Reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ struct Reader {
const auto data = internal::ptr_cast<const std::byte*>(bin.ptr);
return rfl::Bytestring(data, data + bin.size);

} else if constexpr (std::is_same<std::remove_cvref_t<T>,
rfl::Vectorstring>()) {
if (type != MSGPACK_OBJECT_BIN) {
return error("Could not cast to a vectorstring.");
}
const auto bin = _var.via.bin;
const auto data = internal::ptr_cast<const char*>(bin.ptr);
return rfl::Vectorstring(data, data + bin.size);

} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
if (type != MSGPACK_OBJECT_BOOLEAN) {
return error("Could not cast to boolean.");
Expand Down
2 changes: 1 addition & 1 deletion include/rfl/msgpack/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class Writer {
if constexpr (std::is_same<Type, std::string>()) {
msgpack_pack_str(pk_, _var.size());
msgpack_pack_str_body(pk_, _var.c_str(), _var.size());
} else if constexpr (std::is_same<Type, rfl::Bytestring>()) {
} else if constexpr (std::is_same<Type, rfl::Bytestring>() || std::is_same<Type, rfl::Vectorstring>()) {
msgpack_pack_bin(pk_, _var.size());
msgpack_pack_bin_body(pk_, _var.data(), _var.size());
} else if constexpr (std::is_same<Type, bool>()) {
Expand Down
9 changes: 9 additions & 0 deletions include/rfl/ubjson/Reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ class Reader {
const auto data = internal::ptr_cast<const std::byte*>(vec.data());
return rfl::Bytestring(data, data + vec.size());

} else if constexpr (std::is_same<std::remove_cvref_t<T>,
rfl::Vectorstring>()) {
if (!_var.val_->is<std::vector<uint8_t>>()) {
return error("Could not cast to vectorstring.");
}
const auto vec = _var.val_->as<std::vector<uint8_t>>();
const auto data = internal::ptr_cast<const char*>(vec.data());
return rfl::Vectorstring(data, data + vec.size());

} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
if (!_var.val_->is_bool()) {
return error("Could not cast to boolean.");
Expand Down
4 changes: 3 additions & 1 deletion include/rfl/ubjson/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ class Writer {
if constexpr (std::is_same<std::remove_cvref_t<T>, std::string>()) {
encoder_->string_value(_var);
} else if constexpr (std::is_same<std::remove_cvref_t<T>,
rfl::Bytestring>()) {
rfl::Bytestring>() ||
std::is_same<std::remove_cvref_t<T>,
rfl::Vectorstring>()) {
encoder_->byte_string_value(_var);
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
encoder_->bool_value(_var);
Expand Down
23 changes: 23 additions & 0 deletions tests/bson/test_vectorstring.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <iostream>
#include <rfl.hpp>
#include <string>
#include <vector>

#include "write_and_read.hpp"

namespace test_vectorstring {

struct TestStruct {
rfl::Vectorstring vectorstring;
std::vector<rfl::Vectorstring> vectorstrings;
};

TEST(bson, test_vectorstring) {
const auto vstr = rfl::Vectorstring(
{'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'});
const auto test = TestStruct{
.vectorstring = vstr,
.vectorstrings = std::vector<rfl::Vectorstring>({vstr, vstr, vstr})};
write_and_read(test);
}
} // namespace test_vectorstring
20 changes: 20 additions & 0 deletions tests/cbor/test_vectorstring.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#include <rfl.hpp>
#include <string>
#include <vector>

#include "write_and_read.hpp"

namespace test_vectorstring {

struct TestStruct {
rfl::Vectorstring vectorstring;
};
Comment thread
liuzicheng1987 marked this conversation as resolved.

TEST(cbor, test_vectorstring) {
const auto test = TestStruct{
.vectorstring = rfl::Vectorstring({'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'})};

write_and_read(test);
}
} // namespace test_vectorstring
20 changes: 20 additions & 0 deletions tests/msgpack/test_vectorstring.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#include <rfl.hpp>
#include <string>
#include <vector>

#include "write_and_read.hpp"

namespace test_vectorstring {

struct TestStruct {
rfl::Vectorstring vectorstring;
};
Comment thread
liuzicheng1987 marked this conversation as resolved.

TEST(msgpack, test_vectorstring) {
const auto test =
TestStruct{.vectorstring = rfl::Vectorstring({'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'})};

write_and_read(test);
}
} // namespace test_vectorstring
20 changes: 20 additions & 0 deletions tests/ubjson/test_vectorstring.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <iostream>
#include <rfl.hpp>
#include <string>
#include <vector>

#include "write_and_read.hpp"

namespace test_vectorstring {

struct TestStruct {
rfl::Vectorstring vectorstring;
};
Comment thread
liuzicheng1987 marked this conversation as resolved.

TEST(ubjson, test_vectorstring) {
const auto test =
TestStruct{.vectorstring = rfl::Vectorstring({'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'})};

write_and_read(test);
}
} // namespace test_vectorstring
Loading