YARP
Yet Another Robot Platform
ChannelFloat32.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/ChannelFloat32" msg definition:
12 // # This message is used by the PointCloud message to hold optional data
13 // # associated with each point in the cloud. The length of the values
14 // # array should be the same as the length of the points array in the
15 // # PointCloud, and each value should be associated with the corresponding
16 // # point.
17 //
18 // # Channel names in existing practice include:
19 // # "u", "v" - row and column (respectively) in the left stereo image.
20 // # This is opposite to usual conventions but remains for
21 // # historical reasons. The newer PointCloud2 message has no
22 // # such problem.
23 // # "rgb" - For point clouds produced by color stereo cameras. uint8
24 // # (R,G,B) values packed into the least significant 24 bits,
25 // # in order.
26 // # "intensity" - laser or pixel intensity.
27 // # "distance"
28 //
29 // # The channel name should give semantics of the channel (e.g.
30 // # "intensity" instead of "value").
31 // string name
32 //
33 // # The values array should be 1-1 with the elements of the associated
34 // # PointCloud.
35 // float32[] values
36 // Instances of this class can be read and written with YARP ports,
37 // using a ROS-compatible format.
38 
39 #ifndef YARP_ROSMSG_sensor_msgs_ChannelFloat32_h
40 #define YARP_ROSMSG_sensor_msgs_ChannelFloat32_h
41 
42 #include <yarp/os/Wire.h>
43 #include <yarp/os/Type.h>
44 #include <yarp/os/idl/WireTypes.h>
45 #include <string>
46 #include <vector>
47 
48 namespace yarp {
49 namespace rosmsg {
50 namespace sensor_msgs {
51 
53 {
54 public:
55  std::string name;
56  std::vector<yarp::conf::float32_t> values;
57 
59  name(""),
60  values()
61  {
62  }
63 
64  void clear()
65  {
66  // *** name ***
67  name = "";
68 
69  // *** values ***
70  values.clear();
71  }
72 
73  bool readBare(yarp::os::ConnectionReader& connection) override
74  {
75  // *** name ***
76  int len = connection.expectInt32();
77  name.resize(len);
78  if (!connection.expectBlock((char*)name.c_str(), len)) {
79  return false;
80  }
81 
82  // *** values ***
83  len = connection.expectInt32();
84  values.resize(len);
85  if (len > 0 && !connection.expectBlock((char*)&values[0], sizeof(yarp::conf::float32_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(2)) {
97  return false;
98  }
99 
100  // *** name ***
101  if (!reader.readString(name)) {
102  return false;
103  }
104 
105  // *** values ***
106  if (connection.expectInt32() != (BOTTLE_TAG_LIST|BOTTLE_TAG_FLOAT32)) {
107  return false;
108  }
109  int len = connection.expectInt32();
110  values.resize(len);
111  for (int i=0; i<len; i++) {
112  values[i] = (yarp::conf::float32_t)connection.expectFloat32();
113  }
114 
115  return !connection.isError();
116  }
117 
119  bool read(yarp::os::ConnectionReader& connection) override
120  {
121  return (connection.isBareMode() ? readBare(connection)
122  : readBottle(connection));
123  }
124 
125  bool writeBare(yarp::os::ConnectionWriter& connection) const override
126  {
127  // *** name ***
128  connection.appendInt32(name.length());
129  connection.appendExternalBlock((char*)name.c_str(), name.length());
130 
131  // *** values ***
132  connection.appendInt32(values.size());
133  if (values.size()>0) {
134  connection.appendExternalBlock((char*)&values[0], sizeof(yarp::conf::float32_t)*values.size());
135  }
136 
137  return !connection.isError();
138  }
139 
140  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
141  {
142  connection.appendInt32(BOTTLE_TAG_LIST);
143  connection.appendInt32(2);
144 
145  // *** name ***
146  connection.appendInt32(BOTTLE_TAG_STRING);
147  connection.appendInt32(name.length());
148  connection.appendExternalBlock((char*)name.c_str(), name.length());
149 
150  // *** values ***
152  connection.appendInt32(values.size());
153  for (size_t i=0; i<values.size(); i++) {
154  connection.appendFloat32(values[i]);
155  }
156 
157  connection.convertTextMode();
158  return !connection.isError();
159  }
160 
162  bool write(yarp::os::ConnectionWriter& connection) const override
163  {
164  return (connection.isBareMode() ? writeBare(connection)
165  : writeBottle(connection));
166  }
167 
168  // This class will serialize ROS style or YARP style depending on protocol.
169  // If you need to force a serialization style, use one of these classes:
172 
173  // The name for this message, ROS will need this
174  static constexpr const char* typeName = "sensor_msgs/ChannelFloat32";
175 
176  // The checksum for this message, ROS will need this
177  static constexpr const char* typeChecksum = "3d40139cdd33dfedcb71ffeeeb42ae7f";
178 
179  // The source text for this message, ROS will need this
180  static constexpr const char* typeText = "\
181 # This message is used by the PointCloud message to hold optional data\n\
182 # associated with each point in the cloud. The length of the values\n\
183 # array should be the same as the length of the points array in the\n\
184 # PointCloud, and each value should be associated with the corresponding\n\
185 # point.\n\
186 \n\
187 # Channel names in existing practice include:\n\
188 # \"u\", \"v\" - row and column (respectively) in the left stereo image.\n\
189 # This is opposite to usual conventions but remains for\n\
190 # historical reasons. The newer PointCloud2 message has no\n\
191 # such problem.\n\
192 # \"rgb\" - For point clouds produced by color stereo cameras. uint8\n\
193 # (R,G,B) values packed into the least significant 24 bits,\n\
194 # in order.\n\
195 # \"intensity\" - laser or pixel intensity.\n\
196 # \"distance\"\n\
197 \n\
198 # The channel name should give semantics of the channel (e.g.\n\
199 # \"intensity\" instead of \"value\").\n\
200 string name\n\
201 \n\
202 # The values array should be 1-1 with the elements of the associated\n\
203 # PointCloud.\n\
204 float32[] values\n\
205 ";
206 
207  yarp::os::Type getType() const override
208  {
209  yarp::os::Type typ = yarp::os::Type::byName(typeName, typeName);
210  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
211  typ.addProperty("message_definition", yarp::os::Value(typeText));
212  return typ;
213  }
214 };
215 
216 } // namespace sensor_msgs
217 } // namespace rosmsg
218 } // namespace yarp
219 
220 #endif // YARP_ROSMSG_sensor_msgs_ChannelFloat32_h
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
yarp::os::idl::BottleStyle< yarp::rosmsg::sensor_msgs::ChannelFloat32 > bottleStyle
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
bool readBare(yarp::os::ConnectionReader &connection) override
static Type byName(const char *name)
Definition: Type.cpp:176
virtual void appendFloat32(yarp::conf::float32_t data)=0
Send a representation of a 32-bit floating point number to the network connection.
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:138
#define BOTTLE_TAG_FLOAT32
Definition: Bottle.h:26
virtual bool isError() const =0
bool writeBare(yarp::os::ConnectionWriter &connection) const override
The main, catch-all namespace for YARP.
Definition: numeric.h:47
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary...
std::vector< yarp::conf::float32_t > values
static constexpr const char * typeChecksum
virtual bool isBareMode() const =0
Check if the connection is bare mode.
bool readBottle(yarp::os::ConnectionReader &connection) override
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.
static constexpr const char * typeText
virtual bool read(yarp::os::idl::WireReader &reader)
yarp::os::Type getType() const override
virtual bool isError() const =0
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:33
virtual yarp::conf::float32_t expectFloat32()=0
Read a 32-bit floating point number from the network connection.
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
An interface for reading from a network connection.
yarp::os::idl::BareStyle< yarp::rosmsg::sensor_msgs::ChannelFloat32 > rosStyle
float float32_t
Definition: numeric.h:50
A single value (typically within a Bottle).
Definition: Value.h:46
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
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
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
static constexpr const char * typeName
IDL-friendly connection reader.
Definition: WireReader.h:32