Coverage Report

Created: 2025-11-11 06:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/jsoncons/include/jsoncons_ext/bson/bson_encoder.hpp
Line
Count
Source
1
// Copyright 2013-2025 Daniel Parker
2
// Distributed under the Boost license, Version 1.0.
3
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
5
// See https://github.com/danielaparker/jsoncons for latest version
6
7
#ifndef JSONCONS_EXT_BSON_BSON_ENCODER_HPP
8
#define JSONCONS_EXT_BSON_BSON_ENCODER_HPP
9
10
#include <cstddef>
11
#include <cstdint>
12
#include <iterator>
13
#include <limits> // std::numeric_limits
14
#include <memory>
15
#include <string>
16
#include <system_error>
17
#include <utility> // std::move
18
#include <vector>
19
20
#include <jsoncons/config/compiler_support.hpp>
21
#include <jsoncons/config/jsoncons_config.hpp>
22
#include <jsoncons/json_type.hpp>
23
#include <jsoncons/json_visitor.hpp>
24
#include <jsoncons/semantic_tag.hpp>
25
#include <jsoncons/ser_util.hpp>
26
#include <jsoncons/sink.hpp>
27
#include <jsoncons/utility/binary.hpp>
28
#include <jsoncons/utility/byte_string.hpp>
29
#include <jsoncons/utility/unicode_traits.hpp>
30
31
#include <jsoncons_ext/bson/bson_decimal128.hpp>
32
#include <jsoncons_ext/bson/bson_error.hpp>
33
#include <jsoncons_ext/bson/bson_oid.hpp>
34
#include <jsoncons_ext/bson/bson_options.hpp>
35
#include <jsoncons_ext/bson/bson_type.hpp>
36
37
namespace jsoncons { 
38
namespace bson {
39
40
template <typename Sink=jsoncons::binary_stream_sink,typename Allocator=std::allocator<char>>
41
class basic_bson_encoder final : public basic_json_visitor<char>
42
{
43
    enum class decimal_parse_state { start, integer, exp1, exp2, fraction1 };
44
    static constexpr int64_t nanos_in_milli = 1000000;
45
    static constexpr int64_t nanos_in_second = 1000000000;
46
    static constexpr int64_t millis_in_second = 1000;
47
public:
48
    using allocator_type = Allocator;
49
    using char_type = char;
50
    using typename basic_json_visitor<char>::string_view_type;
51
    using sink_type = Sink;
52
53
private:
54
    struct stack_item
55
    {
56
        jsoncons::bson::bson_container_type type_;
57
        std::size_t offset_{0};
58
        std::size_t name_offset_{0};
59
        std::size_t index_{0};
60
61
        stack_item(jsoncons::bson::bson_container_type type, std::size_t offset) noexcept
62
90.1k
           : type_(type), offset_(offset)
63
90.1k
        {
64
90.1k
        }
65
66
        std::size_t offset() const
67
6.00k
        {
68
6.00k
            return offset_;
69
6.00k
        }
70
71
        std::size_t member_offset() const
72
240k
        {
73
240k
            return name_offset_;
74
240k
        }
75
76
        void member_offset(std::size_t offset) 
77
214k
        {
78
214k
            name_offset_ = offset;
79
214k
        }
80
81
        std::size_t next_index()
82
3.50M
        {
83
3.50M
            return index_++;
84
3.50M
        }
85
86
        bool is_object() const
87
3.74M
        {
88
3.74M
            return type_ == jsoncons::bson::bson_container_type::document;
89
3.74M
        }
90
91
92
    };
93
94
    sink_type sink_;
95
    const bson_encode_options options_;
96
    allocator_type alloc_;
97
98
    std::vector<stack_item> stack_;
99
    std::vector<uint8_t> buffer_;
100
    int nesting_depth_{0};
101
public:
102
103
    // Noncopyable and nonmoveable
104
    basic_bson_encoder(const basic_bson_encoder&) = delete;
105
    basic_bson_encoder(basic_bson_encoder&&) = delete;
106
107
    explicit basic_bson_encoder(Sink&& sink, 
108
                                const Allocator& alloc = Allocator())
109
3.07k
       : basic_bson_encoder(std::forward<Sink>(sink),
110
3.07k
                            bson_encode_options(),
111
3.07k
                            alloc)
112
3.07k
    {
113
3.07k
    }
114
115
    explicit basic_bson_encoder(Sink&& sink, 
116
                                const bson_encode_options& options, 
117
                                const Allocator& alloc = Allocator())
118
3.07k
       : sink_(std::forward<Sink>(sink)),
119
3.07k
         options_(options),
120
3.07k
         alloc_(alloc)
121
3.07k
    {
122
3.07k
    }
123
124
    ~basic_bson_encoder() noexcept
125
3.07k
    {
126
3.07k
        sink_.flush();
127
3.07k
    }
128
129
    basic_bson_encoder& operator=(const basic_bson_encoder&) = delete;
130
    basic_bson_encoder& operator=(basic_bson_encoder&&) = delete;
131
132
    void reset()
133
    {
134
        stack_.clear();
135
        buffer_.clear();
136
        nesting_depth_ = 0;
137
    }
138
139
    void reset(Sink&& sink)
140
    {
141
        sink_ = std::move(sink);
142
        reset();
143
    }
144
145
private:
146
    // Implementing methods
147
148
    void visit_flush() override
149
5
    {
150
5
        sink_.flush();
151
5
    }
152
153
    JSONCONS_VISITOR_RETURN_TYPE visit_begin_object(semantic_tag, const ser_context&, std::error_code& ec) override
154
58.8k
    {
155
58.8k
        if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
156
4.35k
        {
157
4.35k
            ec = bson_errc::max_nesting_depth_exceeded;
158
4.35k
            JSONCONS_VISITOR_RETURN;
159
4.35k
        } 
160
54.4k
        if (buffer_.size() > 0)
161
51.3k
        {
162
51.3k
            if (stack_.empty())
163
0
            {
164
0
                ec = bson_errc::expected_bson_document;
165
0
                JSONCONS_VISITOR_RETURN;
166
0
            }
167
51.3k
            before_value(jsoncons::bson::bson_type::document_type);
168
51.3k
        }
169
170
54.4k
        stack_.emplace_back(jsoncons::bson::bson_container_type::document, buffer_.size());
171
54.4k
        buffer_.insert(buffer_.end(), sizeof(int32_t), 0);
172
173
54.4k
        JSONCONS_VISITOR_RETURN;
174
54.4k
    }
175
176
    JSONCONS_VISITOR_RETURN_TYPE visit_end_object(const ser_context&, std::error_code&) override
177
989
    {
178
989
        JSONCONS_ASSERT(!stack_.empty());
179
989
        --nesting_depth_;
180
181
989
        buffer_.push_back(0x00);
182
183
989
        std::size_t length = buffer_.size() - stack_.back().offset();
184
989
        binary::native_to_little(static_cast<uint32_t>(length), buffer_.begin()+stack_.back().offset());
185
186
989
        stack_.pop_back();
187
989
        if (stack_.empty())
188
136
        {
189
136
            for (auto c : buffer_)
190
2.05M
            {
191
2.05M
                sink_.push_back(c);
192
2.05M
            }
193
136
        }
194
989
        JSONCONS_VISITOR_RETURN;
195
989
    }
196
197
    JSONCONS_VISITOR_RETURN_TYPE visit_begin_array(semantic_tag, const ser_context&, std::error_code& ec) override
198
561k
    {
199
561k
        if (JSONCONS_UNLIKELY(++nesting_depth_ > options_.max_nesting_depth()))
200
526k
        {
201
526k
            ec = bson_errc::max_nesting_depth_exceeded;
202
526k
            JSONCONS_VISITOR_RETURN;
203
526k
        } 
204
35.6k
        if (buffer_.size() > 0)
205
35.6k
        {
206
35.6k
            if (stack_.empty())
207
0
            {
208
0
                ec = bson_errc::expected_bson_document;
209
0
                JSONCONS_VISITOR_RETURN;
210
0
            }
211
35.6k
            before_value(jsoncons::bson::bson_type::array_type);
212
35.6k
        }
213
35.6k
        stack_.emplace_back(jsoncons::bson::bson_container_type::array, buffer_.size());
214
35.6k
        buffer_.insert(buffer_.end(), sizeof(int32_t), 0);
215
35.6k
        JSONCONS_VISITOR_RETURN;
216
35.6k
    }
217
218
    JSONCONS_VISITOR_RETURN_TYPE visit_end_array(const ser_context&, std::error_code&) override
219
2.01k
    {
220
2.01k
        JSONCONS_ASSERT(!stack_.empty());
221
2.01k
        --nesting_depth_;
222
223
2.01k
        buffer_.push_back(0x00);
224
225
2.01k
        std::size_t length = buffer_.size() - stack_.back().offset();
226
2.01k
        binary::native_to_little(static_cast<uint32_t>(length), buffer_.begin()+stack_.back().offset());
227
228
2.01k
        stack_.pop_back();
229
2.01k
        if (stack_.empty())
230
0
        {
231
0
            for (auto c : buffer_)
232
0
            {
233
0
                sink_.push_back(c);
234
0
            }
235
0
        }
236
2.01k
        JSONCONS_VISITOR_RETURN;
237
2.01k
    }
238
239
    JSONCONS_VISITOR_RETURN_TYPE visit_key(const string_view_type& name, const ser_context&, std::error_code&) override
240
214k
    {
241
214k
        stack_.back().member_offset(buffer_.size());
242
214k
        buffer_.push_back(0x00); // reserve space for code
243
214k
        for (auto c : name)
244
1.45M
        {
245
1.45M
            buffer_.push_back(c);
246
1.45M
        }
247
214k
        buffer_.push_back(0x00);
248
214k
        JSONCONS_VISITOR_RETURN;
249
214k
    }
250
251
    JSONCONS_VISITOR_RETURN_TYPE visit_null(semantic_tag tag, const ser_context&, std::error_code& ec) override
252
3.61M
    {
253
3.61M
        if (stack_.empty())
254
0
        {
255
0
            ec = bson_errc::expected_bson_document;
256
0
            JSONCONS_VISITOR_RETURN;
257
0
        }
258
3.61M
        switch (tag)
259
3.61M
        {
260
1.22k
            case semantic_tag::undefined:
261
1.22k
                before_value(jsoncons::bson::bson_type::undefined_type);
262
1.22k
                break;
263
3.61M
            default:
264
3.61M
                before_value(jsoncons::bson::bson_type::null_type);
265
3.61M
                break;
266
3.61M
        }
267
3.61M
        JSONCONS_VISITOR_RETURN;
268
3.61M
    }
269
270
    JSONCONS_VISITOR_RETURN_TYPE visit_bool(bool val, semantic_tag, const ser_context&, std::error_code& ec) override
271
1.54k
    {
272
1.54k
        if (stack_.empty())
273
0
        {
274
0
            ec = bson_errc::expected_bson_document;
275
0
            JSONCONS_VISITOR_RETURN;
276
0
        }
277
1.54k
        before_value(jsoncons::bson::bson_type::bool_type);
278
1.54k
        if (val)
279
809
        {
280
809
            buffer_.push_back(0x01);
281
809
        }
282
738
        else
283
738
        {
284
738
            buffer_.push_back(0x00);
285
738
        }
286
287
1.54k
        JSONCONS_VISITOR_RETURN;
288
1.54k
    }
289
290
    JSONCONS_VISITOR_RETURN_TYPE visit_string(const string_view_type& sv, semantic_tag tag, const ser_context&, std::error_code& ec) override
291
28.3k
    {
292
28.3k
        if (stack_.empty())
293
0
        {
294
0
            ec = bson_errc::expected_bson_document;
295
0
            JSONCONS_VISITOR_RETURN;
296
0
        }
297
298
28.3k
        switch (tag)
299
28.3k
        {
300
15.2k
            case semantic_tag::float128:
301
15.2k
            {
302
15.2k
                before_value(jsoncons::bson::bson_type::decimal128_type);
303
15.2k
                decimal128_t dec;
304
15.2k
                auto rc = decimal128_from_chars(sv.data(), sv.data()+sv.size(), dec);
305
15.2k
                if (rc.ec != std::errc{})
306
737
                {
307
737
                    ec = bson_errc::invalid_decimal128_string;
308
737
                    JSONCONS_VISITOR_RETURN;
309
737
                }
310
14.5k
                binary::native_to_little(dec.low,std::back_inserter(buffer_));
311
14.5k
                binary::native_to_little(dec.high,std::back_inserter(buffer_));
312
14.5k
                break;
313
15.2k
            }
314
7.49k
            case semantic_tag::id:
315
7.49k
            {
316
7.49k
                before_value(jsoncons::bson::bson_type::object_id_type);
317
7.49k
                oid_t oid(sv);
318
7.49k
                for (auto b : oid)
319
89.9k
                {
320
89.9k
                    buffer_.push_back(b);
321
89.9k
                }
322
7.49k
                break;
323
15.2k
            }
324
2.38k
            case semantic_tag::regex:
325
2.38k
            {
326
2.38k
                before_value(jsoncons::bson::bson_type::regex_type);
327
2.38k
                std::size_t first = sv.find_first_of('/');
328
2.38k
                std::size_t last = sv.find_last_of('/');
329
2.38k
                if (first == string_view::npos || last == string_view::npos || first == last)
330
0
                {
331
0
                    ec = bson_errc::invalid_regex_string;
332
0
                    JSONCONS_VISITOR_RETURN;
333
0
                }
334
2.38k
                string_view regex = sv.substr(first+1,last-1);
335
2.38k
                for (auto c : regex)
336
4.69M
                {
337
4.69M
                    buffer_.push_back(c);
338
4.69M
                }
339
2.38k
                buffer_.push_back(0x00);
340
2.38k
                string_view options = sv.substr(last+1);
341
2.38k
                for (auto c : options)
342
2.60M
                {
343
2.60M
                    buffer_.push_back(c);
344
2.60M
                }
345
2.38k
                buffer_.push_back(0x00);
346
2.38k
                break;
347
2.38k
            }
348
3.26k
            default:
349
3.26k
                switch (tag)
350
3.26k
                {
351
732
                    case semantic_tag::code:
352
732
                        before_value(jsoncons::bson::bson_type::javascript_type);
353
732
                        break;
354
2.52k
                    default:
355
2.52k
                        before_value(jsoncons::bson::bson_type::string_type);
356
2.52k
                        break;
357
3.26k
                }
358
3.26k
                std::size_t offset = buffer_.size();
359
3.26k
                buffer_.insert(buffer_.end(), sizeof(int32_t), 0);
360
3.26k
                std::size_t string_offset = buffer_.size();
361
3.26k
                auto sink = unicode_traits::validate(sv.data(), sv.size());
362
3.26k
                if (sink.ec != unicode_traits::conv_errc())
363
0
                {
364
0
                    ec = bson_errc::invalid_utf8_text_string;
365
0
                    JSONCONS_VISITOR_RETURN;
366
0
                }
367
3.26k
                for (auto c : sv)
368
3.07M
                {
369
3.07M
                    buffer_.push_back(c);
370
3.07M
                }
371
3.26k
                buffer_.push_back(0x00);
372
3.26k
                std::size_t length = buffer_.size() - string_offset;
373
3.26k
                binary::native_to_little(static_cast<uint32_t>(length), buffer_.begin()+offset);
374
3.26k
                break;
375
28.3k
        }
376
377
28.3k
        JSONCONS_VISITOR_RETURN;
378
28.3k
    }
379
380
    JSONCONS_VISITOR_RETURN_TYPE visit_byte_string(const byte_string_view& b, 
381
        semantic_tag, 
382
        const ser_context&,
383
        std::error_code& ec) override
384
0
    {
385
0
        if (stack_.empty())
386
0
        {
387
0
            ec = bson_errc::expected_bson_document;
388
0
            JSONCONS_VISITOR_RETURN;
389
0
        }
390
0
        before_value(jsoncons::bson::bson_type::binary_type);
391
392
0
        std::size_t offset = buffer_.size();
393
0
        buffer_.insert(buffer_.end(), sizeof(int32_t), 0);
394
0
        std::size_t string_offset = buffer_.size();
395
396
0
        buffer_.push_back(0x80); // default subtype
397
398
0
        for (auto c : b)
399
0
        {
400
0
            buffer_.push_back(c);
401
0
        }
402
0
        std::size_t length = buffer_.size() - string_offset - 1;
403
0
        binary::native_to_little(static_cast<uint32_t>(length), buffer_.begin()+offset);
404
405
0
        JSONCONS_VISITOR_RETURN;
406
0
    }
407
408
    JSONCONS_VISITOR_RETURN_TYPE visit_byte_string(const byte_string_view& b, 
409
        uint64_t ext_tag, 
410
        const ser_context&,
411
        std::error_code& ec) override
412
4.78k
    {
413
4.78k
        if (stack_.empty())
414
0
        {
415
0
            ec = bson_errc::expected_bson_document;
416
0
            JSONCONS_VISITOR_RETURN;
417
0
        }
418
4.78k
        before_value(jsoncons::bson::bson_type::binary_type);
419
420
4.78k
        std::size_t offset = buffer_.size();
421
4.78k
        buffer_.insert(buffer_.end(), sizeof(int32_t), 0);
422
4.78k
        std::size_t string_offset = buffer_.size();
423
424
4.78k
        buffer_.push_back(static_cast<uint8_t>(ext_tag)); // default subtype
425
426
4.78k
        for (auto c : b)
427
5.76M
        {
428
5.76M
            buffer_.push_back(c);
429
5.76M
        }
430
4.78k
        std::size_t length = buffer_.size() - string_offset - 1;
431
4.78k
        binary::native_to_little(static_cast<uint32_t>(length), buffer_.begin()+offset);
432
433
4.78k
        JSONCONS_VISITOR_RETURN;
434
4.78k
    }
435
436
    JSONCONS_VISITOR_RETURN_TYPE visit_int64(int64_t val, 
437
        semantic_tag tag, 
438
        const ser_context&,
439
        std::error_code& ec) override
440
7.43k
    {
441
7.43k
        static constexpr int64_t min_value_div_1000 = (std::numeric_limits<int64_t>::min)() / 1000;
442
7.43k
        static constexpr int64_t max_value_div_1000 = (std::numeric_limits<int64_t>::max)() / 1000;
443
7.43k
        if (stack_.empty())
444
0
        {
445
0
            ec = bson_errc::expected_bson_document;
446
0
            JSONCONS_VISITOR_RETURN;
447
0
        }
448
449
7.43k
        switch (tag)
450
7.43k
        {
451
0
            case semantic_tag::epoch_second:
452
0
                if (val < min_value_div_1000)
453
0
                {
454
0
                    ec = bson_errc::datetime_too_small;
455
0
                    JSONCONS_VISITOR_RETURN;
456
0
                }
457
0
                if (val > max_value_div_1000)
458
0
                {
459
0
                    ec = bson_errc::datetime_too_large;
460
0
                    JSONCONS_VISITOR_RETURN;
461
0
                }
462
0
                before_value(jsoncons::bson::bson_type::datetime_type);
463
0
                binary::native_to_little(val*millis_in_second,std::back_inserter(buffer_));
464
0
                break;
465
937
            case semantic_tag::epoch_milli:
466
937
                before_value(jsoncons::bson::bson_type::datetime_type);
467
937
                binary::native_to_little(val,std::back_inserter(buffer_));
468
937
                break;
469
0
            case semantic_tag::epoch_nano:
470
0
                before_value(jsoncons::bson::bson_type::datetime_type);
471
0
                if (val != 0)
472
0
                {
473
0
                    val /= nanos_in_milli;
474
0
                }
475
0
                binary::native_to_little(static_cast<int64_t>(val),std::back_inserter(buffer_));
476
0
                break;
477
6.49k
            default:
478
6.49k
            {
479
6.49k
                if (val >= (std::numeric_limits<int32_t>::lowest)() && val <= (std::numeric_limits<int32_t>::max)())
480
3.75k
                {
481
3.75k
                    before_value(jsoncons::bson::bson_type::int32_type);
482
3.75k
                    binary::native_to_little(static_cast<uint32_t>(val),std::back_inserter(buffer_));
483
3.75k
                }
484
2.74k
                else 
485
2.74k
                {
486
2.74k
                    before_value(jsoncons::bson::bson_type::int64_type);
487
2.74k
                    binary::native_to_little(static_cast<int64_t>(val),std::back_inserter(buffer_));
488
2.74k
                }
489
6.49k
                break;
490
0
            }
491
7.43k
        }
492
7.43k
        JSONCONS_VISITOR_RETURN;
493
7.43k
    }
494
495
    JSONCONS_VISITOR_RETURN_TYPE visit_uint64(uint64_t val, 
496
        semantic_tag tag, 
497
        const ser_context&,
498
        std::error_code& ec) override
499
2.02k
    {
500
2.02k
        static constexpr uint64_t max_value_div_1000 = (std::numeric_limits<uint64_t>::max)() / 1000;
501
2.02k
        if (stack_.empty())
502
0
        {
503
0
            ec = bson_errc::expected_bson_document;
504
0
            JSONCONS_VISITOR_RETURN;
505
0
        }
506
507
2.02k
        switch (tag)
508
2.02k
        {
509
0
            case semantic_tag::epoch_second:
510
0
                if (val > max_value_div_1000)
511
0
                {
512
0
                    ec = bson_errc::datetime_too_large;
513
0
                    JSONCONS_VISITOR_RETURN;
514
0
                }
515
0
                before_value(jsoncons::bson::bson_type::datetime_type);
516
0
                binary::native_to_little(static_cast<int64_t>(val*millis_in_second),std::back_inserter(buffer_));
517
0
                break;
518
0
            case semantic_tag::epoch_milli:
519
0
                before_value(jsoncons::bson::bson_type::datetime_type);
520
0
                binary::native_to_little(static_cast<int64_t>(val),std::back_inserter(buffer_));
521
0
                break;
522
0
            case semantic_tag::epoch_nano:
523
0
                before_value(jsoncons::bson::bson_type::datetime_type);
524
0
                if (val != 0)
525
0
                {
526
0
                    val /= nanos_in_second;
527
0
                }
528
0
                binary::native_to_little(static_cast<int64_t>(val),std::back_inserter(buffer_));
529
0
                break;
530
2.02k
            default:
531
2.02k
            {
532
2.02k
                if (val <= static_cast<uint64_t>((std::numeric_limits<int32_t>::max)()))
533
805
                {
534
805
                    before_value(jsoncons::bson::bson_type::int32_type);
535
805
                    binary::native_to_little(static_cast<uint32_t>(val),std::back_inserter(buffer_));
536
805
                }
537
1.22k
                else if (val <= static_cast<uint64_t>((std::numeric_limits<int64_t>::max)()))
538
839
                {
539
839
                    before_value(jsoncons::bson::bson_type::int64_type);
540
839
                    binary::native_to_little(static_cast<uint64_t>(val),std::back_inserter(buffer_));
541
839
                }
542
384
                else
543
384
                {
544
384
                    ec = bson_errc::number_too_large;
545
384
                    JSONCONS_VISITOR_RETURN;
546
384
                }
547
1.64k
                break;
548
2.02k
            }
549
2.02k
        }
550
2.02k
        JSONCONS_VISITOR_RETURN;
551
2.02k
    }
552
553
    JSONCONS_VISITOR_RETURN_TYPE visit_double(double val, 
554
        semantic_tag,
555
        const ser_context&,
556
        std::error_code& ec) override
557
1.07k
    {
558
1.07k
        if (stack_.empty())
559
0
        {
560
0
            ec = bson_errc::expected_bson_document;
561
0
            JSONCONS_VISITOR_RETURN;
562
0
        }
563
1.07k
        before_value(jsoncons::bson::bson_type::double_type);
564
1.07k
        binary::native_to_little(val,std::back_inserter(buffer_));
565
1.07k
        JSONCONS_VISITOR_RETURN;
566
1.07k
    }
567
568
    void before_value(uint8_t code) 
569
3.74M
    {
570
3.74M
        JSONCONS_ASSERT(!stack_.empty());
571
3.74M
        if (stack_.back().is_object())
572
240k
        {
573
240k
            buffer_[stack_.back().member_offset()] = code;
574
240k
        }
575
3.50M
        else
576
3.50M
        {
577
3.50M
            buffer_.push_back(code);
578
3.50M
            std::string name = std::to_string(stack_.back().next_index());
579
3.50M
            buffer_.insert(buffer_.end(), name.begin(), name.end());
580
3.50M
            buffer_.push_back(0x00);
581
3.50M
        }
582
3.74M
    }
583
};
584
585
using bson_stream_encoder = basic_bson_encoder<jsoncons::binary_stream_sink>;
586
using bson_bytes_encoder = basic_bson_encoder<jsoncons::bytes_sink<std::vector<uint8_t>>>;
587
588
} // namespace bson
589
} // namespace jsoncons
590
591
#endif // JSONCONS_EXT_BSON_BSON_ENCODER_HPP