YARP
Yet Another Robot Platform
CompressedImage.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 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  // Give source text for class, ROS will need this
189  static std::string typeText()
190  {
191  return std::string("\
192 # This message contains a compressed image\n\
193 \n\
194 Header header # Header timestamp should be acquisition time of image\n\
195  # Header frame_id should be optical frame of camera\n\
196  # origin of frame should be optical center of cameara\n\
197  # +x should point to the right in the image\n\
198  # +y should point down in the image\n\
199  # +z should point into to plane of the image\n\
200 \n\
201 string format # Specifies the format of the data\n\
202  # Acceptable values:\n\
203  # jpeg, png\n\
204 uint8[] data # Compressed image buffer\n\
205 ") + std::string("\n\
206 ================================================================================\n\
207 MSG: std_msgs/Header\n\
209  }
210 
211  std::string getTypeText() const
212  {
214  }
215 
216  // Name the class, ROS will need this
217  yarp::os::Type getType() const override
218  {
219  yarp::os::Type typ = yarp::os::Type::byName("sensor_msgs/CompressedImage", "sensor_msgs/CompressedImage");
220  typ.addProperty("md5sum", yarp::os::Value("8f7a12909da2c9d3332d540a0977563f"));
221  typ.addProperty("message_definition", yarp::os::Value(getTypeText()));
222  return typ;
223  }
224 };
225 
226 } // namespace sensor_msgs
227 } // namespace rosmsg
228 } // namespace yarp
229 
230 #endif // YARP_ROSMSG_sensor_msgs_CompressedImage_h
static std::string typeText()
Definition: Header.h:174
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
#define BOTTLE_TAG_STRING
Definition: Bottle.h:28
bool readBare(yarp::os::ConnectionReader &connection) override
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
virtual std::int8_t expectInt8()=0
Read a 8-bit integer from the network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
#define BOTTLE_TAG_INT8
Definition: Bottle.h:21
static Type byName(const char *name)
Definition: Type.cpp:165
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:127
yarp::rosmsg::std_msgs::Header header
yarp::os::idl::BottleStyle< yarp::rosmsg::sensor_msgs::CompressedImage > bottleStyle
virtual bool isError() const =0
The main, catch-all namespace for YARP.
Definition: numeric.h:47
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary...
bool writeBare(yarp::os::ConnectionWriter &connection) const override
yarp::os::idl::BareStyle< yarp::rosmsg::sensor_msgs::CompressedImage > rosStyle
virtual bool isBareMode() const =0
Check if the connection is bare mode.
An interface for writing to a network connection.
virtual bool write(const yarp::os::idl::WireWriter &writer) const
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
virtual bool read(yarp::os::idl::WireReader &reader)
virtual bool isError() const =0
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Header.h:162
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:30
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
bool readBottle(yarp::os::ConnectionReader &connection) override
An interface for reading from a network connection.
yarp::os::Type getType() const override
A single value (typically within a Bottle).
Definition: Value.h:40
bool readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:330
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
#define BOTTLE_TAG_LIST
Definition: Bottle.h:30
IDL-friendly connection reader.
Definition: WireReader.h:37
virtual void appendInt8(std::int8_t data)=0
Send a representation of a 8-bit integer to the network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Header.h:115
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.