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