Skip to content

Commit

Permalink
Fixed failed array test
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 committed Nov 9, 2024
1 parent ab72519 commit bd40b7a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions include/rfl/ubjson/Reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,14 @@ class Reader {
}
}

rfl::Result<InputArrayType> to_array(InputVarType _var) const noexcept;
rfl::Result<InputArrayType> to_array(const InputVarType& _var) const noexcept;

rfl::Result<InputObjectType> to_object(InputVarType _var) const noexcept;
rfl::Result<InputObjectType> to_object(
const InputVarType& _var) const noexcept;

template <class ArrayReader>
std::optional<Error> read_array(ArrayReader _array_reader,
InputArrayType _arr) const noexcept {
std::optional<Error> read_array(const ArrayReader& _array_reader,
const InputArrayType& _arr) const noexcept {
for (auto& val : _arr.val_->array_range()) {
const auto err = _array_reader.read(InputVarType{&val});
if (err) {
Expand All @@ -105,7 +106,7 @@ class Reader {

template <class ObjectReader>
std::optional<Error> read_object(const ObjectReader& _object_reader,
InputObjectType _obj) const noexcept {
const InputObjectType& _obj) const noexcept {
for (auto& kv : _obj.val_->object_range()) {
_object_reader.read(kv.key(), InputVarType{&kv.value()});
}
Expand Down
4 changes: 2 additions & 2 deletions src/rfl/ubjson/Reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ bool Reader::is_empty(const InputVarType& _var) const noexcept {
}

rfl::Result<Reader::InputArrayType> Reader::to_array(
InputVarType _var) const noexcept {
const InputVarType& _var) const noexcept {
if (!_var.val_->is_array()) {
return Error("Could not cast to an array.");
}
return InputArrayType{_var.val_};
}

rfl::Result<Reader::InputObjectType> Reader::to_object(
InputVarType _var) const noexcept {
const InputVarType& _var) const noexcept {
if (!_var.val_->is_object()) {
return Error("Could not cast to an object.");
}
Expand Down

0 comments on commit bd40b7a

Please sign in to comment.