YARP
Yet Another Robot Platform
String.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/String" msg definition:
9// string data
10// Instances of this class can be read and written with YARP ports,
11// using a ROS-compatible format.
12
13#ifndef YARP_ROSMSG_std_msgs_String_h
14#define YARP_ROSMSG_std_msgs_String_h
15
16#include <yarp/os/Wire.h>
17#include <yarp/os/Type.h>
19#include <string>
20#include <vector>
22namespace yarp {
23namespace rosmsg {
24namespace std_msgs {
25
27{
28public:
29 std::string data;
30
32 data("")
33 {
34 }
35
36 void clear()
37 {
38 // *** data ***
39 data = "";
40 }
41
42 bool readBare(yarp::os::ConnectionReader& connection) override
43 {
44 // *** data ***
45 int len = connection.expectInt32();
46 data.resize(len);
47 if (!connection.expectBlock((char*)data.c_str(), len)) {
48 return false;
49 }
50
51 return !connection.isError();
52 }
53
54 bool readBottle(yarp::os::ConnectionReader& connection) override
55 {
56 connection.convertTextMode();
57 yarp::os::idl::WireReader reader(connection);
58 if (!reader.readListHeader(1)) {
59 return false;
60 }
61
62 // *** data ***
63 if (!reader.readString(data)) {
64 return false;
65 }
66
67 return !connection.isError();
68 }
69
71 bool read(yarp::os::ConnectionReader& connection) override
72 {
73 return (connection.isBareMode() ? readBare(connection)
74 : readBottle(connection));
75 }
76
77 bool writeBare(yarp::os::ConnectionWriter& connection) const override
78 {
79 // *** data ***
80 connection.appendInt32(data.length());
81 connection.appendExternalBlock((char*)data.c_str(), data.length());
82
83 return !connection.isError();
84 }
85
86 bool writeBottle(yarp::os::ConnectionWriter& connection) const override
87 {
88 connection.appendInt32(BOTTLE_TAG_LIST);
89 connection.appendInt32(1);
90
91 // *** data ***
93 connection.appendInt32(data.length());
94 connection.appendExternalBlock((char*)data.c_str(), data.length());
95
96 connection.convertTextMode();
97 return !connection.isError();
98 }
99
101 bool write(yarp::os::ConnectionWriter& connection) const override
102 {
103 return (connection.isBareMode() ? writeBare(connection)
104 : writeBottle(connection));
105 }
106
107 // This class will serialize ROS style or YARP style depending on protocol.
108 // If you need to force a serialization style, use one of these classes:
111
112 // The name for this message, ROS will need this
113 static constexpr const char* typeName = "std_msgs/String";
114
115 // The checksum for this message, ROS will need this
116 static constexpr const char* typeChecksum = "992ce8a1687cec8c8bd883ec73ca41d1";
117
118 // The source text for this message, ROS will need this
119 static constexpr const char* typeText = "\
120string data\n\
121";
122
123 yarp::os::Type getType() const override
124 {
127 typ.addProperty("message_definition", yarp::os::Value(typeText));
128 return typ;
129 }
130};
131
132} // namespace std_msgs
133} // namespace rosmsg
134} // namespace yarp
135
136#endif // YARP_ROSMSG_std_msgs_String_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:43
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:21
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:27
bool readString(std::string &str, bool *is_vocab=nullptr)
Definition: WireReader.cpp:376
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: String.h:42
static constexpr const char * typeChecksum
Definition: String.h:116
yarp::os::idl::BareStyle< yarp::rosmsg::std_msgs::String > rosStyle
Definition: String.h:109
static constexpr const char * typeName
Definition: String.h:113
yarp::os::idl::BottleStyle< yarp::rosmsg::std_msgs::String > bottleStyle
Definition: String.h:110
yarp::os::Type getType() const override
Definition: String.h:123
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: String.h:101
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: String.h:71
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: String.h:77
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: String.h:86
static constexpr const char * typeText
Definition: String.h:119
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: String.h:54
Definition: Bool.h:19
The main, catch-all namespace for YARP.
Definition: dirs.h:16