Added a size check in the arrow reader (#140)

This commit is contained in:
Dr. Patrick Urbanke (劉自成)
2024-07-05 22:58:18 +02:00
committed by GitHub
parent 6ca41f40f7
commit 1ff7f762f1
2 changed files with 30 additions and 0 deletions
+5
View File
@@ -34,6 +34,11 @@ class ArrayReader {
}
std::optional<Error> read(const InputVarType& _var) const {
if (i_ == size_) {
return Error("Expected " + std::to_string(size_) +
" elements, got at least " + std::to_string(size_ + 1) +
".");
}
auto res =
Parser<R, W, std::remove_cvref_t<T>, ProcessorsType>::read(*r_, _var);
if (res) {
+25
View File
@@ -0,0 +1,25 @@
#include <array>
#include <rfl.hpp>
#include <variant>
#include "write_and_read.hpp"
namespace test_array2 {
struct Foo {
std::array<int, 2> v;
};
struct Bar {
std::array<int, 3> v;
};
using FooBar = std::variant<Foo, Bar>; // or rfl::Variant
TEST(json, test_array2) {
FooBar foobar = Bar({1, 2, 3});
write_and_read(foobar, R"({"v":[1,2,3]})");
}
} // namespace test_array2