Squashed 'libs/CommService/' content from commit 7ccc0fc
git-subtree-dir: libs/CommService git-subtree-split: 7ccc0fce88bbc5969df060058cf0fb57abe3bcf9
This commit is contained in:
56
src/CommService/PayLoads/Join.cpp
Normal file
56
src/CommService/PayLoads/Join.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
|
||||
#include <CommService/Convert.hpp>
|
||||
#include <CommService/Message.hpp>
|
||||
#include <CommService/PayLoads/Join.hpp>
|
||||
#include <CommService/transmittable.hpp>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <sstream>
|
||||
#include <loguru.hpp>
|
||||
|
||||
namespace CommService {
|
||||
namespace PayLoads {
|
||||
|
||||
/**
|
||||
* @brief Constructor for generationg a HotPlugJoin object from a received std::vector<unsiged char>
|
||||
*
|
||||
* @param v - the std::vector<unsigned char> representing a message object
|
||||
*/
|
||||
|
||||
Join::Join(std::vector<unsigned char> v)
|
||||
{
|
||||
|
||||
/*
|
||||
* parse the vector
|
||||
*/
|
||||
|
||||
std::memcpy(networkLayerAddress,v.data(),16);
|
||||
v.erase(v.begin(), v.begin()+sizeof(networkLayerAddress));
|
||||
|
||||
|
||||
transportLayerAddress=Convert::fromByteArrayToSimple<std::uint32_t>(v);
|
||||
v.erase(v.begin(), v.begin()+sizeof(transportLayerAddress));
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief converts the whole Payload information into a byte vector
|
||||
*
|
||||
* @param payload - returns the byte vector by call by reference
|
||||
*/
|
||||
std::vector<unsigned char> Join::toByteVector() const
|
||||
{
|
||||
std::vector<unsigned char> bytes;
|
||||
std::vector<unsigned char> convert;
|
||||
|
||||
bytes.resize(16);
|
||||
std::memcpy(bytes.data(),networkLayerAddress,16);
|
||||
|
||||
|
||||
convert=Convert::fromSimpleToByteArray(transportLayerAddress);
|
||||
bytes.insert(std::end(bytes), std::begin(convert), std::end(convert));
|
||||
return bytes;
|
||||
}
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user