YARP
Yet Another Robot Platform
BinPortable-inl.h
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 
7 #ifndef YARP_OS_BINPORTABLE_INL_H
8 #define YARP_OS_BINPORTABLE_INL_H
9 
12 
13 template <class T>
15 {
16  return t;
17 }
18 
19 template <class T>
20 
22 {
23  // An exception will get thrown upon error.
24  // Pending: translate this in expectBlock to a return value.
25  connection.convertTextMode(); // if connection is text-mode, convert!
26  connection.expectBlock((char*)(&t), sizeof(T));
27  return true;
28 }
29 
30 template <class T>
32 {
33  connection.appendBlock((char*)(&t), sizeof(T));
34  connection.convertTextMode(); // if connection is text-mode, convert!
35  return true;
36 }
37 
38 #endif // YARP_OS_BINPORTABLE_INL_H
float t
bool read(ConnectionReader &connection) override
Read this object from a network connection.
bool write(ConnectionWriter &connection) const override
Write this object to a network connection.
T & content()
Get the internal structure that will be read or written.
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 convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
An interface for writing to a network connection.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the network connection.