json_transport.hpp
Go to the documentation of this file.
1 
29 #ifndef JSON_TRANSPORT_JSON_TRANSPORT_HPP
30 #define JSON_TRANSPORT_JSON_TRANSPORT_HPP
31 
33 #include "json_msgs/Json.h"
34 
35 #include <ros/message_traits.h>
36 #include <ros/serialization.h>
37 #include <ros/static_assert.h>
38 
39 namespace json_transport
40 {
42  typedef json_msgs::Json json_msg_t;
43 
44  inline json_t unpack(json_msg_t message)
45  {
46  return json_t::parse(message.json);
47  }
48 
49  inline json_msg_t pack(json_t data)
50  {
51  json_msg_t message{};
52  message.json = data.dump();
53  return message;
54  }
55 }
56 
57 namespace ros
58 {
59 namespace message_traits
60 {
61 
62 ROS_STATIC_ASSERT(sizeof(json_transport::json_t) == 16);
63 
64 template<>
66 {
67  static const char* value()
68  {
70  }
71 
72  static const char* value(const json_transport::json_t&)
73  {
74  return value();
75  }
76 };
77 
78 template<>
80 {
81  static const char* value()
82  {
84  }
85 
86  static const char* value(const json_transport::json_t&)
87  {
88  return value();
89  }
90 };
91 
92 template<>
94 {
95  static const char* value()
96  {
98  }
99 
100  static const char* value(const json_transport::json_t&)
101  {
102  return value();
103  }
104 };
105 } // namespace message_traits
106 
107 namespace serialization
108 {
109 
110 template<>
112 {
113  template<typename Stream>
114  inline static void write(Stream& stream, const json_transport::json_t& json)
115  {
118  }
119 
120  template<typename Stream>
121  inline static void read(Stream& stream, json_transport::json_t& json)
122  {
125  json = json_transport::unpack(message);
126  }
127 
128  inline static uint32_t serializedLength(const json_transport::json_t& json)
129  {
130  return json.dump().length() + 4;
131  }
132 };
133 
134 } // namespace serialization
135 } // namespace ros
136 
137 #endif // JSON_TRANSPORT_JSON_TRANSPORT_HPP
json_t unpack(json_msg_t message)
static const char * value(const json_transport::json_t &)
json_msg_t pack(json_t data)
a class to store JSON values
Definition: json.hpp:85
json_msgs::Json json_msg_t
static const char * value(const json_transport::json_t &)
nlohmann::json json_t
static const char * value(const json_transport::json_t &)
static basic_json parse(detail::input_adapter i, const parser_callback_t cb=nullptr, const bool allow_exceptions=true)
deserialize from a compatible input
Definition: json.hpp:15605
static uint32_t serializedLength(const json_transport::json_t &json)
static void read(Stream &stream, json_transport::json_t &json)
static void write(Stream &stream, const json_transport::json_t &json)
basic_json<> json
default JSON class
Definition: json.hpp:109
string_t dump(const int indent=-1, const char indent_char= ' ', const bool ensure_ascii=false) const
serialization
Definition: json.hpp:11557


json_transport
Author(s): Paul Bovbel
autogenerated on Wed Jan 27 2021 03:58:48