Skip to content

Commit 3500cbb

Browse files
authored
Replace scoped_bson_t with scoped_bson and scoped_bson_view (#1470)
1 parent 1d781e5 commit 3500cbb

36 files changed

+1423
-745
lines changed

src/mongocxx/lib/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
# limitations under the License.
1414

1515
set(mongocxx_sources_private
16-
mongocxx/private/bson.cpp
1716
mongocxx/private/conversions.cpp
1817
mongocxx/private/mongoc.cpp
1918
mongocxx/private/numeric_casting.cpp
19+
mongocxx/private/scoped_bson.cpp
2020
)
2121

2222
set(mongocxx_sources_v_noabi
@@ -255,7 +255,6 @@ set_dist_list(src_mongocxx_lib_DIST
255255
${mongocxx_sources_v_noabi}
256256
${mongocxx_sources_v1}
257257
mongocxx/private/append_aggregate_options.hh
258-
mongocxx/private/bson.hh
259258
mongocxx/private/bulk_write.hh
260259
mongocxx/private/change_stream.hh
261260
mongocxx/private/client_encryption.hh
@@ -277,6 +276,7 @@ set_dist_list(src_mongocxx_lib_DIST
277276
mongocxx/private/read_concern.hh
278277
mongocxx/private/read_preference.hh
279278
mongocxx/private/scoped_bson_value.hh
279+
mongocxx/private/scoped_bson.hh
280280
mongocxx/private/search_index_model.hh
281281
mongocxx/private/search_index_view.hh
282282
mongocxx/private/ssl.hh
@@ -289,6 +289,7 @@ set_dist_list(src_mongocxx_lib_DIST
289289
mongocxx/v_noabi/mongocxx/options/server_api.hh
290290
mongocxx/v_noabi/mongocxx/options/tls.hh
291291
mongocxx/v_noabi/mongocxx/options/transaction.hh
292+
mongocxx/v_noabi/mongocxx/scoped_bson.hh
292293
mongocxx/v1/config/config.hpp.in
293294
mongocxx/v1/config/version.hpp.in
294295
)

src/mongocxx/lib/mongocxx/private/bson.cpp

Lines changed: 0 additions & 129 deletions
This file was deleted.

src/mongocxx/lib/mongocxx/private/bson.hh

Lines changed: 0 additions & 162 deletions
This file was deleted.

src/mongocxx/lib/mongocxx/private/change_stream.hh

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
#include <mongocxx/change_stream.hpp>
2121
#include <mongocxx/exception/query_exception.hpp>
2222

23-
#include <mongocxx/private/bson.hh>
23+
#include <mongocxx/scoped_bson.hh>
24+
2425
#include <mongocxx/private/mongoc.hh>
2526
#include <mongocxx/private/mongoc_error.hh>
2627

@@ -77,22 +78,20 @@ class change_stream::impl {
7778
}
7879

7980
void advance_iterator() {
80-
bson_t const* out;
81+
scoped_bson_view doc;
8182

8283
// Happy-case.
83-
if (libmongoc::change_stream_next(this->change_stream_, &out)) {
84-
this->doc_ = bsoncxx::v_noabi::document::view{bson_get_data(out), out->len};
84+
if (libmongoc::change_stream_next(this->change_stream_, doc.out_ptr())) {
85+
this->doc_ = doc.view();
8586
return;
8687
}
8788

8889
// Check for errors or just nothing left.
8990
bson_error_t error;
90-
if (libmongoc::change_stream_error_document(this->change_stream_, &error, &out)) {
91+
if (libmongoc::change_stream_error_document(this->change_stream_, &error, doc.out_ptr())) {
9192
this->mark_dead();
9293
this->doc_ = bsoncxx::v_noabi::document::view{};
93-
mongocxx::libbson::scoped_bson_t scoped_error_reply{};
94-
bson_copy_to(out, scoped_error_reply.bson_for_init());
95-
throw_exception<query_exception>(scoped_error_reply.steal(), error);
94+
throw_exception<query_exception>(bsoncxx::v_noabi::from_v1(doc.value()), error);
9695
}
9796

9897
// Just nothing left.

0 commit comments

Comments
 (0)