YARP
Yet Another Robot Platform
KeyValue.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 "diagnostic_msgs/KeyValue" msg definition:
9 // string key # what to label this value when viewing
10 // string value # a value to track over time
11 // Instances of this class can be read and written with YARP ports,
12 // using a ROS-compatible format.
13 
14 #ifndef YARP_ROSMSG_diagnostic_msgs_KeyValue_h
15 #define YARP_ROSMSG_diagnostic_msgs_KeyValue_h
16 
17 #include <yarp/os/Wire.h>
18 #include <yarp/os/Type.h>
19 #include <yarp/os/idl/WireTypes.h>
20 #include <string>
21 #include <vector>
22 
23 namespace yarp {
24 namespace rosmsg {
25 namespace diagnostic_msgs {
26 
28 {
29 public:
30  std::string key;
31  std::string value;
32 
34  key(""),
35  value("")
36  {
37  }
38 
39  void clear()
40  {
41  // *** key ***
42  key = "";
43 
44  // *** value ***
45  value = "";
46  }
47 
48  bool readBare(yarp::os::ConnectionReader& connection) override
49  {
50  // *** key ***
51  int len = connection.expectInt32();
52  key.resize(len);
53  if (!connection.expectBlock((char*)key.c_str(), len)) {
54  return false;
55  }
56 
57  // *** value ***
58  len = connection.expectInt32();
59  value.resize(len);
60  if (!connection.expectBlock((char*)value.c_str(), len)) {
61  return false;
62  }
63 
64  return !connection.isError();
65  }
66 
67  bool readBottle(yarp::os::ConnectionReader& connection) override
68  {
69  connection.convertTextMode();
70  yarp::os::idl::WireReader reader(connection);
71  if (!reader.readListHeader(2)) {
72  return false;
73  }
74 
75  // *** key ***
76  if (!reader.readString(key)) {
77  return false;
78  }
79 
80  // *** value ***
81  if (!reader.readString(value)) {
82  return false;
83  }
84 
85  return !connection.isError();
86  }
87 
89  bool read(yarp::os::ConnectionReader& connection) override
90  {
91  return (connection.isBareMode() ? readBare(connection)
92  : readBottle(connection));
93  }
94 
95  bool writeBare(yarp::os::ConnectionWriter& connection) const override
96  {
97  // *** key ***
98  connection.appendInt32(key.length());
99  connection.appendExternalBlock((char*)key.c_str(), key.length());
100 
101  // *** value ***
102  connection.appendInt32(value.length());
103  connection.appendExternalBlock((char*)value.c_str(), value.length());
104 
105  return !connection.isError();
106  }
107 
108  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
109  {
110  connection.appendInt32(BOTTLE_TAG_LIST);
111  connection.appendInt32(2);
112 
113  // *** key ***
114  connection.appendInt32(BOTTLE_TAG_STRING);
115  connection.appendInt32(key.length());
116  connection.appendExternalBlock((char*)key.c_str(), key.length());
117 
118  // *** value ***
119  connection.appendInt32(BOTTLE_TAG_STRING);
120  connection.appendInt32(value.length());
121  connection.appendExternalBlock((char*)value.c_str(), value.length());
122 
123  connection.convertTextMode();
124  return !connection.isError();
125  }
126 
128  bool write(yarp::os::ConnectionWriter& connection) const override
129  {
130  return (connection.isBareMode() ? writeBare(connection)
131  : writeBottle(connection));
132  }
133 
134  // This class will serialize ROS style or YARP style depending on protocol.
135  // If you need to force a serialization style, use one of these classes:
138 
139  // The name for this message, ROS will need this
140  static constexpr const char* typeName = "diagnostic_msgs/KeyValue";
141 
142  // The checksum for this message, ROS will need this
143  static constexpr const char* typeChecksum = "cf57fdc6617a881a88c16e768132149c";
144 
145  // The source text for this message, ROS will need this
146  static constexpr const char* typeText = "\
147 string key # what to label this value when viewing\n\
148 string value # a value to track over time\n\
149 ";
150 
151  yarp::os::Type getType() const override
152  {
154  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
155  typ.addProperty("message_definition", yarp::os::Value(typeText));
156  return typ;
157  }
158 };
159 
160 } // namespace diagnostic_msgs
161 } // namespace rosmsg
162 } // namespace yarp
163 
164 #endif // YARP_ROSMSG_diagnostic_msgs_KeyValue_h
#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
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 readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:382
yarp::os::Type getType() const override
Definition: KeyValue.h:151
static constexpr const char * typeChecksum
Definition: KeyValue.h:143
yarp::os::idl::BareStyle< yarp::rosmsg::diagnostic_msgs::KeyValue > rosStyle
Definition: KeyValue.h:136
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: KeyValue.h:89
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: KeyValue.h:48
static constexpr const char * typeText
Definition: KeyValue.h:146
yarp::os::idl::BottleStyle< yarp::rosmsg::diagnostic_msgs::KeyValue > bottleStyle
Definition: KeyValue.h:137
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: KeyValue.h:128
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: KeyValue.h:95
static constexpr const char * typeName
Definition: KeyValue.h:140
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: KeyValue.h:108
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: KeyValue.h:67
The main, catch-all namespace for YARP.
Definition: dirs.h:16