YARP
Yet Another Robot Platform
CompressedImage.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 // This is an automatically generated file.
7 
8 // Generated from the following "sensor_msgs/CompressedImage" msg definition:
9 // # This message contains a compressed image
10 //
11 // Header header # Header timestamp should be acquisition time of image
12 // # Header frame_id should be optical frame of camera
13 // # origin of frame should be optical center of cameara
14 // # +x should point to the right in the image
15 // # +y should point down in the image
16 // # +z should point into to plane of the image
17 //
18 // string format # Specifies the format of the data
19 // # Acceptable values:
20 // # jpeg, png
21 // uint8[] data # Compressed image buffer
22 // Instances of this class can be read and written with YARP ports,
23 // using a ROS-compatible format.
24 
25 #ifndef YARP_ROSMSG_sensor_msgs_CompressedImage_h
26 #define YARP_ROSMSG_sensor_msgs_CompressedImage_h
27 
28 #include <yarp/os/Wire.h>
29 #include <yarp/os/Type.h>
30 #include <yarp/os/idl/WireTypes.h>
31 #include <string>
32 #include <vector>
34 
35 namespace yarp {
36 namespace rosmsg {
37 namespace sensor_msgs {
38 
40 {
41 public:
43  std::string format;
44  std::vector<std::uint8_t> data;
45 
47  header(),
48  format(""),
49  data()
50  {
51  }
52 
53  void clear()
54  {
55  // *** header ***
56  header.clear();
57 
58  // *** format ***
59  format = "";
60 
61  // *** data ***
62  data.clear();
63  }
64 
65  bool readBare(yarp::os::ConnectionReader& connection) override
66  {
67  // *** header ***
68  if (!header.read(connection)) {
69  return false;
70  }
71 
72  // *** format ***
73  int len = connection.expectInt32();
74  format.resize(len);
75  if (!connection.expectBlock((char*)format.c_str(), len)) {
76  return false;
77  }
78 
79  // *** data ***
80  len = connection.expectInt32();
81  data.resize(len);
82  if (len > 0 && !connection.expectBlock((char*)&data[0], sizeof(std::uint8_t)*len)) {
83  return false;
84  }
85 
86  return !connection.isError();
87  }
88 
89  bool readBottle(yarp::os::ConnectionReader& connection) override
90  {
91  connection.convertTextMode();
92  yarp::os::idl::WireReader reader(connection);
93  if (!reader.readListHeader(3)) {
94  return false;
95  }
96 
97  // *** header ***
98  if (!header.read(connection)) {
99  return false;
100  }
101 
102  // *** format ***
103  if (!reader.readString(format)) {
104  return false;
105  }
106 
107  // *** data ***
108  if (connection.expectInt32() != (BOTTLE_TAG_LIST|BOTTLE_TAG_INT8)) {
109  return false;
110  }
111  int len = connection.expectInt32();
112  data.resize(len);
113  for (int i=0; i<len; i++) {
114  data[i] = (std::uint8_t)connection.expectInt8();
115  }
116 
117  return !connection.isError();
118  }
119 
121  bool read(yarp::os::ConnectionReader& connection) override
122  {
123  return (connection.isBareMode() ? readBare(connection)
124  : readBottle(connection));
125  }
126 
127  bool writeBare(yarp::os::ConnectionWriter& connection) const override
128  {
129  // *** header ***
130  if (!header.write(connection)) {
131  return false;
132  }
133 
134  // *** format ***
135  connection.appendInt32(format.length());
136  connection.appendExternalBlock((char*)format.c_str(), format.length());
137 
138  // *** data ***
139  connection.appendInt32(data.size());
140  if (data.size()>0) {
141  connection.appendExternalBlock((char*)&data[0], sizeof(std::uint8_t)*data.size());
142  }
143 
144  return !connection.isError();
145  }
146 
147  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
148  {
149  connection.appendInt32(BOTTLE_TAG_LIST);
150  connection.appendInt32(3);
151 
152  // *** header ***
153  if (!header.write(connection)) {
154  return false;
155  }
156 
157  // *** format ***
158  connection.appendInt32(BOTTLE_TAG_STRING);
159  connection.appendInt32(format.length());
160  connection.appendExternalBlock((char*)format.c_str(), format.length());
161 
162  // *** data ***
164  connection.appendInt32(data.size());
165  for (size_t i=0; i<data.size(); i++) {
166  connection.appendInt8(data[i]);
167  }
168 
169  connection.convertTextMode();
170  return !connection.isError();
171  }
172 
174  bool write(yarp::os::ConnectionWriter& connection) const override
175  {
176  return (connection.isBareMode() ? writeBare(connection)
177  : writeBottle(connection));
178  }
179 
180  // This class will serialize ROS style or YARP style depending on protocol.
181  // If you need to force a serialization style, use one of these classes:
184 
185  // The name for this message, ROS will need this
186  static constexpr const char* typeName = "sensor_msgs/CompressedImage";
187 
188  // The checksum for this message, ROS will need this
189  static constexpr const char* typeChecksum = "8f7a12909da2c9d3332d540a0977563f";
190 
191  // The source text for this message, ROS will need this
192  static constexpr const char* typeText = "\
193 # This message contains a compressed image\n\
194 \n\
195 Header header # Header timestamp should be acquisition time of image\n\
196  # Header frame_id should be optical frame of camera\n\
197  # origin of frame should be optical center of cameara\n\
198  # +x should point to the right in the image\n\
199  # +y should point down in the image\n\
200  # +z should point into to plane of the image\n\
201 \n\
202 string format # Specifies the format of the data\n\
203  # Acceptable values:\n\
204  # jpeg, png\n\
205 uint8[] data # Compressed image buffer\n\
206 \n\
207 ================================================================================\n\
208 MSG: std_msgs/Header\n\
209 # Standard metadata for higher-level stamped data types.\n\
210 # This is generally used to communicate timestamped data \n\
211 # in a particular coordinate frame.\n\
212 # \n\
213 # sequence ID: consecutively increasing ID \n\
214 uint32 seq\n\
215 #Two-integer timestamp that is expressed as:\n\
216 # * stamp.sec: seconds (stamp_secs) since epoch (in Python the variable is called 'secs')\n\
217 # * stamp.nsec: nanoseconds since stamp_secs (in Python the variable is called 'nsecs')\n\
218 # time-handling sugar is provided by the client library\n\
219 time stamp\n\
220 #Frame this data is associated with\n\
221 # 0: no frame\n\
222 # 1: global frame\n\
223 string frame_id\n\
224 ";
225 
226  yarp::os::Type getType() const override
227  {
229  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
230  typ.addProperty("message_definition", yarp::os::Value(typeText));
231  return typ;
232  }
233 };
234 
235 } // namespace sensor_msgs
236 } // namespace rosmsg
237 } // namespace yarp
238 
239 #endif // YARP_ROSMSG_sensor_msgs_CompressedImage_h
#define BOTTLE_TAG_INT8
Definition: Bottle.h:19
#define BOTTLE_TAG_STRING
Definition: Bottle.h:26
#define BOTTLE_TAG_LIST
Definition: Bottle.h:28
An interface for reading from a network connection.
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
virtual bool isError() const =0
virtual std::int8_t expectInt8()=0
Read a 8-bit integer from the network connection.
An interface for writing to a network connection.
virtual bool isError() const =0
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual void appendInt8(std::int8_t data)=0
Send a representation of a 8-bit integer to the network connection.
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
static Type byName(const char *name)
Definition: Type.cpp:171
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:134
A single value (typically within a Bottle).
Definition: Value.h:45
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:23
virtual bool read(yarp::os::idl::WireReader &reader)
virtual bool write(const yarp::os::idl::WireWriter &writer) const
IDL-friendly connection reader.
Definition: WireReader.h:30
bool readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:382
bool readBottle(yarp::os::ConnectionReader &connection) override
bool readBare(yarp::os::ConnectionReader &connection) override
static constexpr const char * typeText
yarp::os::idl::BareStyle< yarp::rosmsg::sensor_msgs::CompressedImage > rosStyle
static constexpr const char * typeName
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
yarp::os::idl::BottleStyle< yarp::rosmsg::sensor_msgs::CompressedImage > bottleStyle
yarp::rosmsg::std_msgs::Header header
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
static constexpr const char * typeChecksum
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
yarp::os::Type getType() const override
bool writeBare(yarp::os::ConnectionWriter &connection) const override
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Header.h:159
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Header.h:112
The main, catch-all namespace for YARP.
Definition: dirs.h:16