nlohmann_parsers.cpp
Go to the documentation of this file.
1 #include "nlohmann_parsers.h"
2 
3 #define FMT_HEADER_ONLY
4 #include "fmt/format.h"
5 
7 {
9 
10  auto ts = _json.find("/timestamp");
11  if( ts != _json.end() && ts.value().is_number())
12  {
13  timestamp = ts.value().get<double>();
14  }
15  }
16 
17  std::string key;
18  for(const auto& el: _json.items())
19  {
20  double value = 0;
21  if( el.value().is_boolean())
22  {
23  value = el.value().get<bool>();
24  }
25  else if( el.value().is_number())
26  {
27  value = el.value().get<double>();
28  }
29  else{
30  continue;
31  }
32  key = fmt::format("{}/{}", _topic_name, el.key() );
33  auto plot_data = &(getSeries(key));
34  plot_data->pushBack( {timestamp, value} );
35  }
36  return true;
37 }
38 
40  double timestamp)
41 {
43  msg.data() + msg.size() ).flatten();
44  return parseMessageImpl(timestamp);
45 }
46 
48  double timestamp)
49 {
51  msg.data()+ msg.size()).flatten();
52  return parseMessageImpl(timestamp);
53 }
54 
56  double timestamp)
57 {
59  msg.data()+ msg.size() ).flatten();
60  return parseMessageImpl(timestamp);
61 }
62 
64  double timestamp)
65 {
67  msg.data()+ msg.size() ).flatten();
68  return parseMessageImpl(timestamp);
69 }
enum MQTTPropertyCodes value
const uint8_t * data() const
FMT_INLINE std::basic_string< Char > format(const S &format_str, Args &&...args)
Definition: core.h:2081
iterator end() noexcept
returns an iterator to one past the last element
Definition: json.hpp:21120
bool parseMessageImpl(double timestamp)
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_cbor(InputType &&i, const bool strict=true, const bool allow_exceptions=true, const cbor_tag_handler_t tag_handler=cbor_tag_handler_t::error)
create a JSON value from an input in CBOR format
Definition: json.hpp:24043
size_t size() const
bool parseMessage(const MessageRef msg, double timestamp) override
nlohmann::json _json
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_msgpack(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
create a JSON value from an input in MessagePack format
Definition: json.hpp:24186
bool parseMessage(const MessageRef msg, double timestamp) override
iterator find(KeyT &&key)
find an element in a JSON object
Definition: json.hpp:20895
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json from_bson(InputType &&i, const bool strict=true, const bool allow_exceptions=true)
Create a JSON value from an input in BSON format.
Definition: json.hpp:24415
static JSON_HEDLEY_WARN_UNUSED_RESULT basic_json parse(InputType &&i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true, const bool ignore_comments=false)
deserialize from a compatible input
Definition: json.hpp:23219
bool parseMessage(const MessageRef msg, double timestamp) override
PlotData & getSeries(const std::string &key)
iteration_proxy< iterator > items() noexcept
helper to access iterator member functions in range-based for
Definition: json.hpp:21439
bool parseMessage(const MessageRef msg, double timestamp) override
def timestamp()
Definition: mqttsas.py:143
reference value() const
return the value of an iterator
Definition: json.hpp:11464


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:09