|
21 | 21 | #include "../Box.hpp" |
22 | 22 | #include "../Bytestring.hpp" |
23 | 23 | #include "../Result.hpp" |
| 24 | +#include "../Vectorstring.hpp" |
24 | 25 | #include "../always_false.hpp" |
25 | 26 | #include "../internal/ptr_cast.hpp" |
26 | 27 |
|
@@ -112,18 +113,34 @@ struct Reader { |
112 | 113 | } |
113 | 114 |
|
114 | 115 | } else if constexpr (std::is_same<std::remove_cvref_t<T>, |
115 | | - rfl::Bytestring>()) { |
| 116 | + rfl::Bytestring>() || |
| 117 | + std::is_same<std::remove_cvref_t<T>, |
| 118 | + rfl::Vectorstring>()) { |
| 119 | + using VectorType = std::remove_cvref_t<T>; |
| 120 | + using ValueType = typename VectorType::value_type; |
116 | 121 | if (btype != BSON_TYPE_BINARY) { |
117 | | - return error("Could not cast to bytestring."); |
| 122 | + if constexpr (std::is_same<std::remove_cvref_t<T>, |
| 123 | + rfl::Bytestring>()) { |
| 124 | + return error("Could not cast to bytestring."); |
| 125 | + } else { |
| 126 | + return error("Could not cast to vectorstring."); |
| 127 | + } |
118 | 128 | } |
119 | 129 | if (value.v_binary.subtype != BSON_SUBTYPE_BINARY) { |
120 | | - return error( |
121 | | - "The BSON subtype must be a binary in order to read into a " |
122 | | - "bytestring."); |
| 130 | + if constexpr (std::is_same<std::remove_cvref_t<T>, |
| 131 | + rfl::Bytestring>()) { |
| 132 | + return error( |
| 133 | + "The BSON subtype must be a binary in order to read into a " |
| 134 | + "bytestring."); |
| 135 | + } else { |
| 136 | + return error( |
| 137 | + "The BSON subtype must be a binary in order to read into a " |
| 138 | + "vectorstring."); |
| 139 | + } |
123 | 140 | } |
124 | 141 | const auto data = |
125 | | - internal::ptr_cast<const std::byte*>(value.v_binary.data); |
126 | | - return rfl::Bytestring(data, data + value.v_binary.data_len); |
| 142 | + internal::ptr_cast<const ValueType*>(value.v_binary.data); |
| 143 | + return VectorType(data, data + value.v_binary.data_len); |
127 | 144 |
|
128 | 145 | } else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) { |
129 | 146 | if (btype != BSON_TYPE_BOOL) { |
|
0 commit comments