13 #ifndef ROBOT_DATA_HPP_ 14 #define ROBOT_DATA_HPP_ 20 #include <ecl/containers.hpp> 64 payloadBase(
const bool is_dynamic_ =
false,
const unsigned char length_ = 0 )
66 , is_dynamic(is_dynamic_)
74 virtual bool serialise(ecl::PushAndPop<unsigned char> & byteStream)=0;
75 virtual bool deserialise(ecl::PushAndPop<unsigned char> & byteStream)=0;
84 if (buffer.size() <
sizeof(T))
86 V =
static_cast<unsigned char>(buffer.pop_front());
88 unsigned int size_value(
sizeof(T));
89 for (
unsigned int i = 1; i < size_value; i++)
91 V |= ((
static_cast<unsigned char>(buffer.pop_front())) << (8 * i));
96 void buildBytes(
const T & V, ecl::PushAndPop<unsigned char> & buffer)
98 unsigned int size_value(
sizeof(T));
99 for (
unsigned int i = 0; i < size_value; i++)
101 buffer.push_back(static_cast<unsigned char>((V >> (i * 8)) & 0xff));
113 inline void payloadBase::buildVariable<float>(
float & V, ecl::PushAndPop<unsigned char> & buffer)
115 if (buffer.size() < 4)
118 ui =
static_cast<unsigned char>(buffer.pop_front());
120 unsigned int size_value(4);
121 for (
unsigned int i = 1; i < size_value; i++)
123 ui |= ((
static_cast<unsigned char>(buffer.pop_front())) << (8 * i));
126 V =
reinterpret_cast<float&
>(ui);
130 inline void payloadBase::buildBytes<float>(
const float & V, ecl::PushAndPop<unsigned char> & buffer)
132 if (buffer.size() < 4)
134 unsigned int size_value(4);
135 unsigned int ui(reinterpret_cast<const unsigned int&>(V));
136 for (
unsigned int i = 0; i < size_value; i++)
138 buffer.push_back(static_cast<unsigned char>((ui >> (i * 8)) & 0xff));
const unsigned char length
virtual bool deserialise(ecl::PushAndPop< unsigned char > &byteStream)=0
Provides base class for payloads.
virtual bool serialise(ecl::PushAndPop< unsigned char > &byteStream)=0
payloadBase(const bool is_dynamic_=false, const unsigned char length_=0)
void buildVariable(T &V, ecl::PushAndPop< unsigned char > &buffer)
void buildBytes(const T &V, ecl::PushAndPop< unsigned char > &buffer)