datatamer_parser.cpp
Go to the documentation of this file.
1 
2 #include "datatamer_parser.h"
5 
6 using namespace PJ;
7 
9 {
10 public:
11  MsgParserImpl(const std::string& topic_name, const std::string& type_name,
12  const std::string& schema, PJ::PlotDataMapRef& data)
13  : MessageParser(topic_name, data), topic_name_(topic_name)
14  {
15  schema_ = DataTamerParser::BuilSchemaFromText(schema);
16  }
17 
18  bool parseMessage(const MessageRef serialized_msg, double& timestamp) override
19  {
20  auto callback = [this, timestamp](const std::string& series_name,
22  auto name = fmt::format("{}/{}", topic_name_, series_name);
23  auto& plot_data = _plot_data.getOrCreateNumeric(name);
24 
25  double value = std::visit([](auto&& v) { return static_cast<double>(v); }, var);
26 
27  plot_data.pushBack({ timestamp, value });
28  };
29 
31  snapshot.schema_hash = schema_.hash;
32 
33  DataTamerParser::BufferSpan msg_buffer = { serialized_msg.data(),
34  serialized_msg.size() };
35 
36  const uint32_t mask_size = DataTamerParser::Deserialize<uint32_t>(msg_buffer);
37  snapshot.active_mask.data = msg_buffer.data;
38  snapshot.active_mask.size = mask_size;
39  msg_buffer.trimFront(mask_size);
40 
41  const uint32_t payload_size = DataTamerParser::Deserialize<uint32_t>(msg_buffer);
42  snapshot.payload.data = msg_buffer.data;
43  snapshot.payload.size = payload_size;
44 
45  DataTamerParser::ParseSnapshot(schema_, snapshot, callback);
46  return true;
47  }
48 
49 private:
51 
52  struct TimeSeries
53  {
54  std::string name;
56  PlotData* plot_data = nullptr;
57  };
58 
59  std::string topic_name_;
60  std::vector<TimeSeries> timeseries_;
61 };
62 
63 MessageParserPtr ParserDataTamer::createParser(const std::string& topic_name,
64  const std::string& type_name,
65  const std::string& schema,
67 {
68  return std::make_shared<MsgParserImpl>(topic_name, type_name, schema, data);
69 }
DataTamerParser::Schema
DataTamer uses a simple "flat" schema of key/value pairs (each pair is a "field").
Definition: data_tamer_parser.hpp:77
PJ::TimeseriesBase
Definition: timeseries.h:16
PJ::MessageParserPtr
std::shared_ptr< MessageParser > MessageParserPtr
Definition: messageparser_base.h:136
MsgParserImpl::timeseries_
std::vector< TimeSeries > timeseries_
Definition: datatamer_parser.cpp:60
DataTamerParser::SnapshotView::payload
BufferSpan payload
serialized data containing all the values, ordered as in the schema
Definition: data_tamer_parser.hpp:102
DataTamerParser::BasicType
BasicType
Definition: data_tamer_parser.hpp:19
PJ::MessageRef::data
const uint8_t * data() const
Definition: messageparser_base.h:51
sol::type_name
std::string type_name(lua_State *L, type t)
Definition: sol.hpp:8079
DataTamerParser::VarNumber
std::variant< bool, char, int8_t, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, uint64_t, float, double > VarNumber
Definition: data_tamer_parser.hpp:43
sol::var
auto var(V &&v)
Definition: sol.hpp:18020
data_tamer_parser.hpp
MsgParserImpl::TimeSeries::name
std::string name
Definition: datatamer_parser.cpp:54
DataTamerParser::BuilSchemaFromText
Schema BuilSchemaFromText(const std::string &txt)
Definition: data_tamer_parser.hpp:216
MsgParserImpl::MsgParserImpl
MsgParserImpl(const std::string &topic_name, const std::string &type_name, const std::string &schema, PJ::PlotDataMapRef &data)
Definition: datatamer_parser.cpp:11
PJ::MessageParser
The MessageParser is the base class used to parse a message with a specific encoding+schema.
Definition: messageparser_base.h:75
format
auto format(const text_style &ts, const S &format_str, const Args &... args) -> std::basic_string< Char >
Definition: color.h:543
DataTamerParser::SnapshotView::active_mask
BufferSpan active_mask
Definition: data_tamer_parser.hpp:99
DataTamerParser::BufferSpan::trimFront
void trimFront(size_t n)
Definition: data_tamer_parser.hpp:50
MsgParserImpl::parseMessage
bool parseMessage(const MessageRef serialized_msg, double &timestamp) override
Definition: datatamer_parser.cpp:18
MsgParserImpl
Definition: datatamer_parser.cpp:8
MsgParserImpl::schema_
DataTamerParser::Schema schema_
Definition: datatamer_parser.cpp:50
DataTamerParser::BufferSpan::data
const uint8_t * data
Definition: data_tamer_parser.hpp:47
PJ::MessageRef
Definition: messageparser_base.h:28
core.h
MsgParserImpl::TimeSeries::type
DataTamerParser::BasicType type
Definition: datatamer_parser.cpp:55
DataTamerParser::BufferSpan
Definition: data_tamer_parser.hpp:45
PJ
Definition: dataloader_base.h:16
mqtt_test.data
dictionary data
Definition: mqtt_test.py:22
PJ::MessageRef::size
size_t size() const
Definition: messageparser_base.h:61
DataTamerParser::ParseSnapshot
bool ParseSnapshot(const Schema &schema, SnapshotView snapshot, const NumberCallback &callback_number, const CustomCallback &callback_custom=NullCustomCallback)
Definition: data_tamer_parser.hpp:411
ParserDataTamer::createParser
PJ::MessageParserPtr createParser(const std::string &topic_name, const std::string &type_name, const std::string &schema, PJ::PlotDataMapRef &data) override
Definition: datatamer_parser.cpp:63
PJ::PlotDataMapRef
Definition: plotdata.h:34
DataTamerParser::SnapshotView
Definition: data_tamer_parser.hpp:88
DataTamerParser::BufferSpan::size
size_t size
Definition: data_tamer_parser.hpp:48
DataTamerParser::SnapshotView::schema_hash
size_t schema_hash
Unique identifier of the schema.
Definition: data_tamer_parser.hpp:91
MsgParserImpl::TimeSeries
Definition: datatamer_parser.cpp:52
datatamer_parser.h
MsgParserImpl::topic_name_
std::string topic_name_
Definition: datatamer_parser.cpp:59


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:44