ADD: Message container and Join Message

This commit is contained in:
Henry Winkel
2022-11-11 14:36:57 +01:00
parent 2d077f4ff4
commit 3006f79883
13 changed files with 545 additions and 23 deletions

View File

@@ -0,0 +1,53 @@
#include "WHISPER/Messages/Message.hpp"
#include "WHISPER/Messages/Protos/join.pb.h"
#include <WHISPER/Messages/Join.hpp>
#include <memory>
namespace WHISPER {
Join::Join(std::string receivedMessage){
msg = messages::header::Message();
try {
msg.ParseFromString(receivedMessage);
topic_ = msg.topic();
sourceType_ = msg.sourcetype();
msgType_ = msg.msgtype();
joinMessage = messages::join::Join();
if ( msg.payload_size()) {
if (msg.payload().begin()->Is<messages::join::Join>()) {
msg.payload().begin()->UnpackTo(&joinMessage);
}
}
port = joinMessage.port();
sourceAddr = joinMessage.srcaddress();
} catch (const std::exception& e) {
LOG_S(ERROR)<<e.what();
}
}
WHISPER::Join::Join(std::uint32_t deviceID,std::uint32_t topic, MsgType Type, SourceType src,std::uint32_t port, std::string addr):
Message(deviceID,topic,Type,src),port(port),sourceAddr(addr)
{
joinMessage = messages::join::Join();
joinMessage.set_port(port);
joinMessage.set_srcaddress(sourceAddr);
LOG_S(INFO)<< "join message befor packing:" << joinMessage.ByteSizeLong();
auto test = std::make_shared<google::protobuf::Any>();
test->PackFrom(joinMessage);
addPayLoad(test);
}
}