git-subtree-dir: libs/CommService git-subtree-split: 7ccc0fce88bbc5969df060058cf0fb57abe3bcf9
70 lines
2.0 KiB
C++
70 lines
2.0 KiB
C++
/*
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
*/
|
|
|
|
/**
|
|
* @file
|
|
* @brief implementation file for the Pong payload
|
|
* @author Dominik Meyer <dmeyer@hsu-hh.de>
|
|
* @date 2019-02-06
|
|
* @copyright 2019 no yet defined
|
|
*/
|
|
#include "CommService/Convert.hpp"
|
|
#include <CommService/PayLoads/Pong.hpp>
|
|
#include <CommService/transmittable.hpp>
|
|
#include <cstring>
|
|
#include <vector>
|
|
#include <sstream>
|
|
|
|
namespace CommService {
|
|
namespace PayLoads {
|
|
/**
|
|
* @brief Constructor for generationg a Pong object from a received std::vector<unsiged char>
|
|
*
|
|
* @param v - the std::vector<unsigned char> representing a message object
|
|
*/
|
|
Pong::Pong(std::vector<unsigned char> v)
|
|
{
|
|
|
|
/*
|
|
* parse the vector
|
|
*/
|
|
|
|
pingMessageID= Convert::fromByteArrayToSimple<uint64_t>(v);
|
|
v.erase(v.begin(), v.begin()+sizeof(pingMessageID));
|
|
|
|
pingTransmissionTime=Convert::fromByteArrayToSimple<int>(v);
|
|
v.erase(v.begin(), v.begin()+sizeof(pingTransmissionTime));
|
|
|
|
sequenceNr=Convert::fromByteArrayToSimple<uint64_t>(v);
|
|
v.erase(v.begin(), v.begin()+sizeof(sequenceNr));
|
|
}
|
|
|
|
|
|
/**
|
|
* @brief converts the whole Payload information into a byte vector
|
|
*
|
|
* @param payload - returns the byte vector by call by reference
|
|
*/
|
|
std::vector<unsigned char> Pong::toByteVector() const
|
|
{
|
|
std::vector<unsigned char> bytes;
|
|
std::vector<unsigned char> convert;
|
|
|
|
convert=Convert::fromSimpleToByteArray(pingMessageID);
|
|
bytes.insert(std::end(bytes), std::begin(convert), std::end(convert));
|
|
convert.clear();
|
|
|
|
convert=Convert::fromSimpleToByteArray(pingTransmissionTime);
|
|
bytes.insert(std::end(bytes), std::begin(convert), std::end(convert));
|
|
convert.clear();
|
|
|
|
convert=Convert::fromSimpleToByteArray(sequenceNr);
|
|
bytes.insert(std::end(bytes), std::begin(convert), std::end(convert));
|
|
|
|
return bytes;
|
|
}
|
|
};
|
|
}; |