Skip to content

Commit

Permalink
Made sure that the BSON tests run through
Browse files Browse the repository at this point in the history
  • Loading branch information
liuzicheng1987 committed Jan 18, 2024
1 parent a10ddf8 commit c928158
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
19 changes: 10 additions & 9 deletions include/rfl/bson/Writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <variant>
#include <vector>

#include "../Box.hpp"
#include "../Ref.hpp"
#include "../Result.hpp"
#include "../always_false.hpp"
Expand Down Expand Up @@ -102,20 +103,20 @@ class Writer {

OutputObjectType add_object_to_array(
const size_t _size, OutputArrayType* _parent) const noexcept {
subdocs_->push_back(BSONType{});
subdocs_->emplace_back(rfl::Box<BSONType>());
bson_array_builder_append_document_begin(_parent->val_,
&subdocs_->back().val_);
return OutputObjectType(&subdocs_->back().val_, IsArray{_parent->val_});
&(subdocs_->back()->val_));
return OutputObjectType(&subdocs_->back()->val_, IsArray{_parent->val_});
}

OutputObjectType add_object_to_object(
const std::string& _name, const size_t _size,
OutputObjectType* _parent) const noexcept {
subdocs_->push_back(BSONType{});
subdocs_->emplace_back(rfl::Box<BSONType>());
bson_append_document_begin(_parent->val_, _name.c_str(),
static_cast<int>(_name.size()),
&subdocs_->back().val_);
return OutputObjectType(&subdocs_->back().val_, IsObject{_parent->val_});
&(subdocs_->back()->val_));
return OutputObjectType(&subdocs_->back()->val_, IsObject{_parent->val_});
}

template <class T>
Expand All @@ -131,7 +132,7 @@ class Writer {
static_cast<double>(_var));
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
bson_array_builder_append_int64(_parent->val_,
static_cast<std::int32_t>(_var));
static_cast<std::int64_t>(_var));
} else {
static_assert(rfl::always_false_v<T>, "Unsupported type.");
}
Expand All @@ -155,7 +156,7 @@ class Writer {
} else if constexpr (std::is_integral<std::remove_cvref_t<T>>()) {
bson_append_int64(_parent->val_, _name.c_str(),
static_cast<int>(_name.size()),
static_cast<std::int32_t>(_var));
static_cast<std::int64_t>(_var));
} else {
static_assert(rfl::always_false_v<T>, "Unsupported type.");
}
Expand Down Expand Up @@ -211,7 +212,7 @@ class Writer {
bson_t* const doc_;

/// Contain all of the subdocuments.
const rfl::Ref<std::vector<BSONType>> subdocs_;
const rfl::Ref<std::vector<rfl::Box<BSONType>>> subdocs_;
};

} // namespace bson
Expand Down
2 changes: 1 addition & 1 deletion tests/bson/tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ int main() {
test_enum::test();
test_flag_enum::test();
test_flag_enum_with_int::test();
// test_map::test();
test_map::test();
test_map_with_key_validation::test();
test_variant::test();
test_field_variant::test();
Expand Down

0 comments on commit c928158

Please sign in to comment.