mirror of
https://codeberg.org/DawnMagnet/reflect-cpp
synced 2026-11-28 22:06:19 +08:00
fix build with llvm-18 by changing Bytestring type to std::vector instead of deprecated std::basic_string<std::byte> (#369)
This commit is contained in:
@@ -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<std::byte>`. Supported by Avro, BSON, Cap'n Proto, CBOR, flexbuffers, msgpack and UBJSON.
|
||||
- `rfl::Bytestring`: An alias for `std::vector<std::byte>`. 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.
|
||||
|
||||
+1
-6
@@ -5,15 +5,10 @@
|
||||
```cpp
|
||||
namespace rfl {
|
||||
|
||||
using Bytestring = std::basic_string<std::byte>;
|
||||
using Bytestring = std::vector<std::byte>;
|
||||
|
||||
}
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
#define RFL_BYTESTRING_HPP_
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace rfl {
|
||||
|
||||
using Bytestring = std::basic_string<std::byte>;
|
||||
using Bytestring = std::vector<std::byte>;
|
||||
|
||||
} // namespace rfl
|
||||
|
||||
|
||||
@@ -75,7 +75,8 @@ struct Reader {
|
||||
if (err) {
|
||||
return error("Could not cast to bytestring.");
|
||||
}
|
||||
return rfl::Bytestring(static_cast<const std::byte*>(ptr), size - 1);
|
||||
const auto data = internal::ptr_cast<const std::byte*>(ptr);
|
||||
return rfl::Bytestring(data, data + size - 1);
|
||||
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
||||
if (type != AVRO_BOOLEAN) {
|
||||
return rfl::error("Could not cast to boolean.");
|
||||
|
||||
@@ -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<const std::byte*>(value.v_binary.data),
|
||||
value.v_binary.data_len);
|
||||
const auto data =
|
||||
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>, bool>()) {
|
||||
if (btype != BSON_TYPE_BOOL) {
|
||||
return error("Could not cast to boolean.");
|
||||
|
||||
@@ -69,8 +69,8 @@ class Reader {
|
||||
return error("Could not cast to bytestring.");
|
||||
}
|
||||
const auto data = _var.val_.as<capnp::Data>();
|
||||
return rfl::Bytestring(internal::ptr_cast<const std::byte*>(data.begin()),
|
||||
data.size());
|
||||
const auto begin = internal::ptr_cast<const std::byte*>(data.begin());
|
||||
return rfl::Bytestring(begin, begin + data.size());
|
||||
|
||||
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
||||
if (type != capnp::DynamicValue::BOOL) {
|
||||
|
||||
@@ -77,8 +77,8 @@ class Reader {
|
||||
return error("Could not cast to bytestring.");
|
||||
}
|
||||
const auto vec = _var.val_->as<std::vector<uint8_t>>();
|
||||
return rfl::Bytestring(internal::ptr_cast<const std::byte*>(vec.data()),
|
||||
vec.size());
|
||||
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>, bool>()) {
|
||||
if (!_var.val_->is_bool()) {
|
||||
return error("Could not cast to boolean.");
|
||||
|
||||
@@ -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<const std::byte*>(blob.data()),
|
||||
blob.size());
|
||||
const auto data = internal::ptr_cast<const std::byte*>(blob.data());
|
||||
return rfl::Bytestring(data, data + blob.size());
|
||||
} else if constexpr (std::is_same<std::remove_cvref_t<T>, bool>()) {
|
||||
if (!_var.IsBool()) {
|
||||
return error("Could not cast to boolean.");
|
||||
|
||||
@@ -36,9 +36,6 @@ class StringConverter {
|
||||
|
||||
/// Transforms a string to the matching enum.
|
||||
static Result<EnumType> 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 {
|
||||
|
||||
@@ -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<const std::byte*>(bin.ptr),
|
||||
bin.size);
|
||||
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>, bool>()) {
|
||||
if (type != MSGPACK_OBJECT_BOOLEAN) {
|
||||
return error("Could not cast to boolean.");
|
||||
|
||||
@@ -77,8 +77,8 @@ class Reader {
|
||||
return error("Could not cast to bytestring.");
|
||||
}
|
||||
const auto vec = _var.val_->as<std::vector<uint8_t>>();
|
||||
return rfl::Bytestring(internal::ptr_cast<const std::byte*>(vec.data()),
|
||||
vec.size());
|
||||
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>, bool>()) {
|
||||
if (!_var.val_->is_bool()) {
|
||||
return error("Could not cast to boolean.");
|
||||
|
||||
Reference in New Issue
Block a user