YARP
Yet Another Robot Platform
WireWriter.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 #ifndef YARP_OS_IDL_WIREWRITER_H
7 #define YARP_OS_IDL_WIREWRITER_H
8 
9 #include <yarp/conf/numeric.h>
10 
11 #include <yarp/os/api.h>
12 
13 #include <yarp/os/Bottle.h>
15 #include <yarp/os/Vocab.h>
17 #include <yarp/os/idl/WireReader.h>
18 
19 #include <string>
20 
21 namespace yarp {
22 namespace os {
23 namespace idl {
24 
30 {
31 public:
33 
34  WireWriter(WireReader& reader);
35 
36  ~WireWriter();
37 
38  bool isNull() const;
39 
40  bool write(const WirePortable& obj) const;
41 
42  bool write(const yarp::os::PortWriter& obj) const;
43 
44  bool writeNested(const WirePortable& obj) const;
45 
46  bool writeNested(const yarp::os::PortWriter& obj) const;
47 
48  bool writeBool(bool x) const;
49 
50  bool writeI8(std::int8_t x) const;
51 
52  bool writeI16(std::int16_t x) const;
53 
54  bool writeI32(std::int32_t x) const;
55 
56  bool writeI64(std::int64_t x) const;
57 
58  bool writeFloat32(yarp::conf::float32_t x) const;
59 
60  bool writeFloat64(yarp::conf::float64_t x) const;
61 
62  bool writeUI8(std::uint8_t x) const;
63 
64  bool writeUI16(std::uint16_t x) const;
65 
66  bool writeUI32(std::uint32_t x) const;
67 
68  bool writeUI64(std::uint64_t x) const;
69 
70  bool writeVocab32(yarp::conf::vocab32_t x) const;
71 
72  bool writeVocab32(char a, char b = 0, char c = 0, char d = 0) const
73  {
74  return writeVocab32(yarp::os::createVocab32(a, b, c, d));
75  }
76 
77  // If the string is longer than 4 characters, only the first 4 are used.
78  bool writeVocab32(const std::string& str) const
79  {
80  return writeVocab32(yarp::os::Vocab32::encode(str));
81  }
82 
83  bool writeSizeT(std::size_t x) const;
84 
85  bool isValid() const;
86 
87  bool isError() const;
88 
89  bool writeTag(const char* tag, int split, int len) const;
90 
91  bool writeString(const std::string& tag) const;
92 
93  bool writeBinary(const std::string& tag) const;
94 
95  bool writeListHeader(int len) const;
96 
97  bool writeListBegin(int tag, std::uint32_t len) const;
98 
99  bool writeSetBegin(int tag, std::uint32_t len) const;
100 
101  bool writeMapBegin(int tag, int tag2, std::uint32_t len) const;
102 
103  bool writeListEnd() const;
104 
105  bool writeSetEnd() const;
106 
107  bool writeMapEnd() const;
108 
109  bool writeOnewayResponse() const;
110 
111 #ifndef YARP_NO_DEPRECATED // Since YARP 3.0.0
112  YARP_DEPRECATED_MSG("Use writeI8 instead")
113  bool writeByte(std::int8_t x) const
114  {
115  return writeI8(x);
116  }
117 
118  YARP_DEPRECATED_MSG("Use writeFloat64 instead")
119  bool writeDouble(double x) const
120  {
121  return writeFloat64(static_cast<yarp::conf::float64_t>(x));
122  }
123 #endif // YARP_NO_DEPRECATED
124 
125 #ifndef YARP_NO_DEPRECATED // Since YARP 3.5.0
126  YARP_DEPRECATED_MSG("Use writeVocab32 instead")
127  bool writeVocab(std::int32_t x) const
128  {
129  return writeVocab32(x);
130  }
131 #endif // YARP_NO_DEPRECATED
132 
133 private:
134  bool get_mode;
136  bool get_is_vocab32;
137  mutable bool need_ok;
138  ConnectionWriter& writer;
139 };
140 
141 } // namespace idl
142 } // namespace os
143 } // namespace yarp
144 
145 #endif // YARP_OS_IDL_WIREWRITER_H
An interface for writing to a network connection.
Interface implemented by all objects that can write themselves to the network, such as Bottle objects...
Definition: PortWriter.h:24
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:23
IDL-friendly connection reader.
Definition: WireReader.h:30
IDL-friendly connection writer.
Definition: WireWriter.h:30
bool writeVocab32(char a, char b=0, char c=0, char d=0) const
Definition: WireWriter.h:72
bool writeVocab32(const std::string &str) const
Definition: WireWriter.h:78
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2885
std::string get_string(const std::string &key, bool *found=nullptr)
Read a string from an environment variable.
Definition: environment.h:68
ContainerT split(const typename ContainerT::value_type &s, std::basic_regex< typename ContainerT::value_type::value_type > regex)
Utility to split a string by a separator, into a vector of strings.
Definition: string.h:27
std::int32_t vocab32_t
Definition: numeric.h:78
double float64_t
Definition: numeric.h:77
float float32_t
Definition: numeric.h:76
bool isValid()
Check if time is valid (non-zero).
Definition: Time.cpp:314
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
Definition: Vocab.cpp:11
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.
Definition: Vocab.h:28
bool write(const ImageOf< PixelRgb > &src, const std::string &dest, image_fileformat format=FORMAT_PPM)
Definition: ImageFile.cpp:1099
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition: system.h:336
#define YARP_os_API
Definition: api.h:18