Create a bsoncxx document from bson bytes

I have the bytes \x0e\x00\x00\x00\x02a\x00\x02\x00\x00\x00b\x00\x00 from, let’s say, a binary file. The data is basically {‘a’: ‘b’}. I want to construct a bson document using the bsoncxx c++ library. How should I go about doing this? I could not find something related in the documentation.

#include <bsoncxx/builder/stream/helpers.hpp>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/builder/stream/array.hpp>
#include <bsoncxx/types.hpp>
#include <bsoncxx/config/prelude.hpp>


int main() {
    unsigned char data[] = {0x0e, 0x00, 0x00, 0x00, 0x02a, 0x00, 0x02, 0x00, 0x00, 0x00b, 0x00, 0x00};

    std::cout << sizeof(data) << std::endl;
    bsoncxx::document::view x(data, sizeof(data));
    std::cout << bsoncxx::to_json(x) << std::endl;
}

I get the following error:

terminate called after throwing an instance of 'bsoncxx::v_noabi::exception' what(): unknown bsoncxx error code

but only sometimes. otherwise it crashes with

Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

btw, I used the pymongo bson library to encode the dictionary {‘a’: ‘b’} into a bson byte string and I split that into the char array data above. I suspect that’s not exactly correct?

This is what bson.encode({'a': 'b'}) returned: b'\x0e\x00\x00\x00\x02a\x00\x02\x00\x00\x00b\x00\x00'