YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
PortablePair.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
8
11
12
14 Portable& head,
15 Portable& body)
16{
17 // if someone connects in text mode, use standard
18 // text-to-binary mapping
19 connection.convertTextMode();
20
21 std::int32_t header = connection.expectInt32();
22 if (header != BOTTLE_TAG_LIST) {
23 return false;
24 }
25 std::int32_t len = connection.expectInt32();
26 if (len != 2) {
27 return false;
28 }
29
30 bool ok = head.read(connection);
31 if (ok) {
32 ok = body.read(connection);
33 }
34 return ok;
35}
36
38 const Portable& head,
39 const Portable& body)
40{
41 connection.appendInt32(BOTTLE_TAG_LIST); // nested structure
42 connection.appendInt32(2); // with two elements
43 bool ok = head.write(connection);
44 if (ok) {
45 ok = body.write(connection);
46 }
47
48 if (ok) {
49 // if someone connects in text mode,
50 // let them see something readable.
51 connection.convertTextMode();
52 }
53
54 return ok;
55}
#define BOTTLE_TAG_LIST
Definition Bottle.h:28
A mini-server for performing network communication in the background.
An interface for reading from a network connection.
An interface for writing to a network connection.
static bool writePair(ConnectionWriter &connection, const Portable &head, const Portable &body)
Writes an object pair to a network connection.
static bool readPair(ConnectionReader &connection, Portable &head, Portable &body)
Reads an object pair from a network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
Definition Portable.h:25
bool read(ConnectionReader &reader) override=0
Read this object from a network connection.
bool write(ConnectionWriter &writer) const override=0
Write this object to a network connection.