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
str
std::string str(const T &t)
Definition: UserAssistedSegmenterGuiWidgetController.cpp:42
armarx::data::from_json
void from_json(const nlohmann::json &j, PackagePath &pp)
Definition: json_conversions.h:45
armarx::armem::server::ltm::processor::DataConverter::ConversionResult::suffix
std::string suffix
Definition: Converter.h:28
armarx::aron::data::detail::SpecializedVariantBase< data::dto::Dict, Dict >::DynamicCast
static PointerType DynamicCast(const VariantPtr &n)
Definition: SpecializedVariant.h:117
armarx::aron::Path
The Path class.
Definition: Path.h:36
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::armem::server::ltm::processor::converter::data::object::BsonConverter::_convert
ConversionResult _convert(const aron::data::DictPtr &data) final
Definition: BsonConverter.cpp:14
armarx::armem::server::ltm::processor::converter::data::ObjectConverter::convert
ConversionResult convert(const aron::data::VariantPtr &data) final
Definition: Converter.cpp:7
armarx::data::to_json
void to_json(nlohmann::json &j, const PackagePath &pp)
Definition: json_conversions.h:36
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
BsonConverter.h
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::armem::server::ltm::processor::converter::data::object
Definition: BsonConverter.cpp:8
armarx::armem::server::ltm::processor::DataConverter::ConversionResult
Definition: Converter.h:25
armarx::armem::server::ltm::processor::DataConverter::ConversionResult::data
std::vector< unsigned char > data
Definition: Converter.h:27