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 writeSizeT(std::size_t x, bool skip_tag = false) const;
82
83 bool isValid() const;
84
85 bool isError() const;
86
87 bool writeTag(const char* tag, int split, int len) const;
88
89 bool writeString(const std::string& str, bool skip_tag = false) const;
90
91 bool writeBlock(const char* data, size_t len) const;
92
93 bool writeBinary(const std::string& blob, bool skip_tag = false) const;
94
95 bool writeListHeader(int len) const;
96
97 bool writeListBegin(int tag, size_t len) const;
98
99 bool writeSetBegin(int tag, size_t len) const;
100
101 bool writeMapBegin(int tag, int tag2, size_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 void flush();
112
113private:
114 bool get_mode {false};
115 YARP_SUPPRESS_DLL_INTERFACE_WARNING_ARG(std::string) get_string;
116 bool get_is_vocab32 {false};
117 mutable bool need_ok {false};
118 ConnectionReader* reader {nullptr};
119 ConnectionWriter& writer;
120};
121
122} // namespace yarp::os::idl
123
124#endif // YARP_OS_IDL_WIREWRITER_H
void split(const std::string &s, char delim, std::vector< std::string > &elements)
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 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
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: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