/* * 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 * @date 2019-02-06 * @copyright 2019 no yet defined */ #include "CommService/Convert.hpp" #include #include #include #include #include namespace CommService { namespace PayLoads { /** * @brief Constructor for generationg a Pong object from a received std::vector * * @param v - the std::vector representing a message object */ Pong::Pong(std::vector v) { /* * parse the vector */ pingMessageID= Convert::fromByteArrayToSimple(v); v.erase(v.begin(), v.begin()+sizeof(pingMessageID)); pingTransmissionTime=Convert::fromByteArrayToSimple(v); v.erase(v.begin(), v.begin()+sizeof(pingTransmissionTime)); sequenceNr=Convert::fromByteArrayToSimple(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 Pong::toByteVector() const { std::vector bytes; std::vector 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; } }; };