31 static std::unordered_map<std::string, ValueType> names = {
42 {
"FLOAT", ValueType::FLOAT },
43 {
"DOUBLE", ValueType::DOUBLE }
45 auto const it = names.find(str);
55 std::memcpy(&out, ptr + offset,
sizeof(T));
65 const std::string &schema,
68 topic_name_(topic_name)
71 std::istringstream ss(schema);
74 while (std::getline(ss, line))
77 auto pos = line.find(
' ');
78 ts.
name = line.substr(0, pos);
88 const auto* msg_ptr = serialized_msg.
data();
89 uint32_t flags_size = Deserialize<uint32_t>(msg_ptr, offset);
91 thread_local std::vector<uint8_t> enable_vector;
92 enable_vector.resize(flags_size);
93 std::memcpy(enable_vector.data(), msg_ptr + offset, flags_size);
96 const uint32_t remaining_bytes = Deserialize<uint32_t>(msg_ptr, offset);
98 if(remaining_bytes + offset != serialized_msg.
size())
100 throw std::runtime_error(
"DataTamerParser: corrupted size");
103 for(
size_t i=0; i<timeseries_.size(); i++)
105 const uint8_t flag_byte = enable_vector[i/8];
106 const uint8_t mask = uint8_t(1 << (i%8));
110 switch(timeseries_[i].
type)
113 val =
static_cast<double>(Deserialize<uint8_t>(msg_ptr, offset));
116 val =
static_cast<double>(Deserialize<uint16_t>(msg_ptr, offset));
119 val =
static_cast<double>(Deserialize<uint32_t>(msg_ptr, offset));
122 val =
static_cast<double>(Deserialize<uint64_t>(msg_ptr, offset));
126 val =
static_cast<double>(Deserialize<int8_t>(msg_ptr, offset));
129 val =
static_cast<double>(Deserialize<int16_t>(msg_ptr, offset));
132 val =
static_cast<double>(Deserialize<int32_t>(msg_ptr, offset));
135 val =
static_cast<double>(Deserialize<int64_t>(msg_ptr, offset));
139 val =
static_cast<double>(Deserialize<float>(msg_ptr, offset));
142 val = Deserialize<double>(msg_ptr, offset);
147 auto& ts = timeseries_[i];
150 ts.plot_data = &(_plot_data.addNumeric(topic_name_ +
"/" + ts.name)->second);
152 ts.plot_data->pushBack({timestamp, val});
173 const std::string &schema,
176 return std::make_shared<DataTamerParser>(topic_name,
type_name, schema,
data);
DataTamer::ValueType type
PJ::MessageParserPtr createParser(const std::string &topic_name, const std::string &type_name, const std::string &schema, PJ::PlotDataMapRef &data) override
std::vector< TimeSeries > timeseries_
std::shared_ptr< MessageParser > MessageParserPtr
DataTamerParser(const std::string &topic_name, const std::string &type_name, const std::string &schema, PJ::PlotDataMapRef &data)
ValueType FromStr(std::string const &str)
std::string type_name(lua_State *L, type t)
const T & move(const T &v)
const uint8_t * data() const
The MessageParser is the base class used to parse a message with a specific encoding+schema.
bool parseMessage(const MessageRef serialized_msg, double ×tamp) override
T Deserialize(const uint8_t *ptr, int &offset)