BsonConverter.cpp
Go to the documentation of this file.
1#include "BsonConverter.h"
2
3#include <bsoncxx/builder/stream/array.hpp>
4#include <bsoncxx/builder/stream/document.hpp>
5#include <bsoncxx/builder/stream/helpers.hpp>
6#include <bsoncxx/json.hpp>
7
9{
10 namespace bsoncxxbuilder = bsoncxx::builder::stream;
11 namespace bsoncxxdoc = bsoncxx::document;
12
15 {
16 auto [jsonVec, str] = jsonConverter.convert(data);
17 std::string json(jsonVec.begin(), jsonVec.end());
18 auto view = bsoncxx::from_json(json).view();
19
20 std::vector<unsigned char> bson(view.length());
21 if (view.length() > 0)
22 {
23 std::memcpy(bson.data(), view.data(), view.length());
24 }
25 return {bson, str};
26 }
27
30 {
31 bsoncxx::document::view view(data.data.data(), data.data.size());
32 nlohmann::json json = bsoncxx::to_json(view);
33 std::string str = json.dump();
34
36 j.data = std::vector<unsigned char>(str.begin(), str.end());
37 j.suffix = data.suffix;
38
39 auto v = jsonConverter.convert(j, p);
41 }
42} // namespace armarx::armem::server::ltm::processor::converter::data::object
std::string str(const T &t)
ConversionResult _convert(const aron::data::DictPtr &data) final
The Path class.
Definition Path.h:36
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42