YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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>
18
19#include <string>
20
21namespace yarp::os::idl {
22
28{
29public:
31
32 WireWriter(WireReader& reader);
33
35
36 bool isNull() const;
37
38 bool write(const WirePortable& obj) const;
39
40 bool write(const yarp::os::PortWriter& obj) const;
41
42 bool writeNested(const WirePortable& obj) const;
43
44 bool writeNested(const yarp::os::PortWriter& obj) const;
45
46 bool writeBool(bool x, bool skip_tag = false) const;
47
48 bool writeI8(std::int8_t x, bool skip_tag = false) const;
49
50 bool writeI16(std::int16_t x, bool skip_tag = false) const;
51
52 bool writeI32(std::int32_t x, bool skip_tag = false) const;
53
54 bool writeI64(std::int64_t x, bool skip_tag = false) const;
55
56 bool writeFloat32(yarp::conf::float32_t x, bool skip_tag = false) const;
57
58 bool writeFloat64(yarp::conf::float64_t x, bool skip_tag = false) const;
59
60 bool writeUI8(std::uint8_t x, bool skip_tag = false) const;
61
62 bool writeUI16(std::uint16_t x, bool skip_tag = false) const;
63
64 bool writeUI32(std::uint32_t x, bool skip_tag = false) const;
65
66 bool writeUI64(std::uint64_t x, bool skip_tag = false) const;
67
68 bool writeVocab32(yarp::conf::vocab32_t x, bool skip_tag = false) const;
69
70 bool writeVocab32(char a, char b = 0, char c = 0, char d = 0, bool skip_tag = false) const
71 {
72 return writeVocab32(yarp::os::createVocab32(a, b, c, d));
73 }
74
75 // If the string is longer than 4 characters, only the first 4 are used.
76 bool writeVocab32(const std::string& str, bool skip_tag = false) const
77 {
78 return writeVocab32(yarp::os::Vocab32::encode(str));
79 }
80
81 bool writeVocab64(yarp::conf::vocab64_t x, bool skip_tag = false) const;
82
83 bool writeVocab64(char a, char b = 0, char c = 0, char d = 0, char e = 0,char f = 0,char g = 0,char h = 0, bool skip_tag = false) const
84 {
85 return writeVocab64(yarp::os::createVocab64(a, b, c, d, e, f, g, h));
86 }
87
88 // If the string is longer than 8 characters, only the first 8 are used.
89 bool writeVocab64(const std::string& str, bool skip_tag = false) const
90 {
91 return writeVocab64(yarp::os::Vocab64::encode64(str));
92 }
93
94 bool writeSizeT(std::size_t x, bool skip_tag = false) const;
95
96 bool isValid() const;
97
98 bool isError() const;
99
100 bool writeTag(const char* tag, int split, int len) const;
101
102 bool writeString(const std::string& str, bool skip_tag = false) const;
103
104 bool writeBlock(const char* data, size_t len) const;
105
106 bool writeBinary(const std::string& blob, bool skip_tag = false) const;
107
108 bool writeListHeader(int len) const;
109
110 bool writeListBegin(int tag, size_t len) const;
111
112 bool writeSetBegin(int tag, size_t len) const;
113
114 bool writeMapBegin(int tag, int tag2, size_t len) const;
115
116 bool writeListEnd() const;
117
118 bool writeSetEnd() const;
119
120 bool writeMapEnd() const;
121
122 bool writeOnewayResponse() const;
123
124 void flush();
125
126private:
127 bool get_mode {false};
128 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) get_string;
129 bool get_is_vocab32 {false};
130 mutable bool need_ok {false};
131 ConnectionReader* reader {nullptr};
132 ConnectionWriter& writer;
133};
134
135} // namespace yarp::os::idl
136
137#endif // YARP_OS_IDL_WIREWRITER_H
A mini-server for performing network communication in the background.
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:23
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
IDL-friendly connection reader.
Definition WireReader.h:27
IDL-friendly connection writer.
Definition WireWriter.h:28
bool writeVocab32(const std::string &str, bool skip_tag=false) const
Definition WireWriter.h:76
bool writeVocab64(char a, char b=0, char c=0, char d=0, char e=0, char f=0, char g=0, char h=0, bool skip_tag=false) const
Definition WireWriter.h:83
bool writeVocab64(const std::string &str, bool skip_tag=false) const
Definition WireWriter.h:89
bool writeVocab32(char a, char b=0, char c=0, char d=0, bool skip_tag=false) const
Definition WireWriter.h:70
std::int32_t vocab32_t
Definition numeric.h:78
std::int64_t vocab64_t
Definition numeric.h:79
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
Definition Vocab32.cpp:11
NetInt64 encode64(const std::string &str)
Convert a string into a vocabulary identifier.
Definition Vocab64.cpp:10
constexpr yarp::conf::vocab64_t createVocab64(char a, char b=0, char c=0, char d=0, char e=0, char f=0, char g=0, char h=0)
Create a vocab from chars.
Definition Vocab64.h:26
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.
Definition Vocab32.h:27
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(x)
Suppress MSVC C4251 warning for the declaration.
Definition system.h:338
#define YARP_os_API
Definition api.h:18