YARP
Yet Another Robot Platform
UInt32MultiArray.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 "std_msgs/UInt32MultiArray" msg definition:
9 // # Please look at the MultiArrayLayout message definition for
10 // # documentation on all multiarrays.
11 //
12 // MultiArrayLayout layout # specification of data layout
13 // uint32[] data # array of data
14 //
15 // Instances of this class can be read and written with YARP ports,
16 // using a ROS-compatible format.
17 
18 #ifndef YARP_ROSMSG_std_msgs_UInt32MultiArray_h
19 #define YARP_ROSMSG_std_msgs_UInt32MultiArray_h
20 
21 #include <yarp/os/Wire.h>
22 #include <yarp/os/Type.h>
23 #include <yarp/os/idl/WireTypes.h>
24 #include <string>
25 #include <vector>
27 
28 namespace yarp {
29 namespace rosmsg {
30 namespace std_msgs {
31 
33 {
34 public:
36  std::vector<std::uint32_t> data;
37 
39  layout(),
40  data()
41  {
42  }
43 
44  void clear()
45  {
46  // *** layout ***
47  layout.clear();
48 
49  // *** data ***
50  data.clear();
51  }
52 
53  bool readBare(yarp::os::ConnectionReader& connection) override
54  {
55  // *** layout ***
56  if (!layout.read(connection)) {
57  return false;
58  }
59 
60  // *** data ***
61  int len = connection.expectInt32();
62  data.resize(len);
63  if (len > 0 && !connection.expectBlock((char*)&data[0], sizeof(std::uint32_t)*len)) {
64  return false;
65  }
66 
67  return !connection.isError();
68  }
69 
70  bool readBottle(yarp::os::ConnectionReader& connection) override
71  {
72  connection.convertTextMode();
73  yarp::os::idl::WireReader reader(connection);
74  if (!reader.readListHeader(2)) {
75  return false;
76  }
77 
78  // *** layout ***
79  if (!layout.read(connection)) {
80  return false;
81  }
82 
83  // *** data ***
84  if (connection.expectInt32() != (BOTTLE_TAG_LIST|BOTTLE_TAG_INT32)) {
85  return false;
86  }
87  int len = connection.expectInt32();
88  data.resize(len);
89  for (int i=0; i<len; i++) {
90  data[i] = (std::uint32_t)connection.expectInt32();
91  }
92 
93  return !connection.isError();
94  }
95 
97  bool read(yarp::os::ConnectionReader& connection) override
98  {
99  return (connection.isBareMode() ? readBare(connection)
100  : readBottle(connection));
101  }
102 
103  bool writeBare(yarp::os::ConnectionWriter& connection) const override
104  {
105  // *** layout ***
106  if (!layout.write(connection)) {
107  return false;
108  }
109 
110  // *** data ***
111  connection.appendInt32(data.size());
112  if (data.size()>0) {
113  connection.appendExternalBlock((char*)&data[0], sizeof(std::uint32_t)*data.size());
114  }
115 
116  return !connection.isError();
117  }
118 
119  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
120  {
121  connection.appendInt32(BOTTLE_TAG_LIST);
122  connection.appendInt32(2);
123 
124  // *** layout ***
125  if (!layout.write(connection)) {
126  return false;
127  }
128 
129  // *** data ***
131  connection.appendInt32(data.size());
132  for (size_t i=0; i<data.size(); i++) {
133  connection.appendInt32(data[i]);
134  }
135 
136  connection.convertTextMode();
137  return !connection.isError();
138  }
139 
141  bool write(yarp::os::ConnectionWriter& connection) const override
142  {
143  return (connection.isBareMode() ? writeBare(connection)
144  : writeBottle(connection));
145  }
146 
147  // This class will serialize ROS style or YARP style depending on protocol.
148  // If you need to force a serialization style, use one of these classes:
151 
152  // The name for this message, ROS will need this
153  static constexpr const char* typeName = "std_msgs/UInt32MultiArray";
154 
155  // The checksum for this message, ROS will need this
156  static constexpr const char* typeChecksum = "4d6a180abc9be191b96a7eda6c8a233d";
157 
158  // The source text for this message, ROS will need this
159  static constexpr const char* typeText = "\
160 # Please look at the MultiArrayLayout message definition for\n\
161 # documentation on all multiarrays.\n\
162 \n\
163 MultiArrayLayout layout # specification of data layout\n\
164 uint32[] data # array of data\n\
165 \n\
166 \n\
167 ================================================================================\n\
168 MSG: std_msgs/MultiArrayLayout\n\
169 # The multiarray declares a generic multi-dimensional array of a\n\
170 # particular data type. Dimensions are ordered from outer most\n\
171 # to inner most.\n\
172 \n\
173 MultiArrayDimension[] dim # Array of dimension properties\n\
174 uint32 data_offset # padding elements at front of data\n\
175 \n\
176 # Accessors should ALWAYS be written in terms of dimension stride\n\
177 # and specified outer-most dimension first.\n\
178 # \n\
179 # multiarray(i,j,k) = data[data_offset + dim_stride[1]*i + dim_stride[2]*j + k]\n\
180 #\n\
181 # A standard, 3-channel 640x480 image with interleaved color channels\n\
182 # would be specified as:\n\
183 #\n\
184 # dim[0].label = \"height\"\n\
185 # dim[0].size = 480\n\
186 # dim[0].stride = 3*640*480 = 921600 (note dim[0] stride is just size of image)\n\
187 # dim[1].label = \"width\"\n\
188 # dim[1].size = 640\n\
189 # dim[1].stride = 3*640 = 1920\n\
190 # dim[2].label = \"channel\"\n\
191 # dim[2].size = 3\n\
192 # dim[2].stride = 3\n\
193 #\n\
194 # multiarray(i,j,k) refers to the ith row, jth column, and kth channel.\n\
195 \n\
196 ================================================================================\n\
197 MSG: std_msgs/MultiArrayDimension\n\
198 string label # label of given dimension\n\
199 uint32 size # size of given dimension (in type units)\n\
200 uint32 stride # stride of given dimension\n\
201 ";
202 
203  yarp::os::Type getType() const override
204  {
206  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
207  typ.addProperty("message_definition", yarp::os::Value(typeText));
208  return typ;
209  }
210 };
211 
212 } // namespace std_msgs
213 } // namespace rosmsg
214 } // namespace yarp
215 
216 #endif // YARP_ROSMSG_std_msgs_UInt32MultiArray_h
#define BOTTLE_TAG_INT32
Definition: Bottle.h:21
#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
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 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 write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
static constexpr const char * typeChecksum
bool writeBare(yarp::os::ConnectionWriter &connection) const override
yarp::os::Type getType() const override
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
std::vector< std::uint32_t > data
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
bool readBottle(yarp::os::ConnectionReader &connection) override
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
yarp::rosmsg::std_msgs::MultiArrayLayout layout
yarp::os::idl::BareStyle< yarp::rosmsg::std_msgs::UInt32MultiArray > rosStyle
yarp::os::idl::BottleStyle< yarp::rosmsg::std_msgs::UInt32MultiArray > bottleStyle
static constexpr const char * typeText
static constexpr const char * typeName
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: Bool.h:19
The main, catch-all namespace for YARP.
Definition: dirs.h:16