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,72 @@
#include "WHISPER/Messages/Protos/join.pb.h"
#include <WHISPER/Messages/Message.hpp>
#include <memory>
namespace WHISPER {
Message::Message(std::string stringMessage)
{
msg = messages::header::Message();
try {
msg.ParseFromString(stringMessage);
topic_ = msg.topic();
sourceType_ = msg.sourcetype();
msgType_ = msg.msgtype();
} catch (const std::exception& e) {
LOG_S(ERROR)<<e.what();
}
}
Message::Message(std::int32_t deviceId,std::uint32_t topic, MsgType Type,SourceType src):topic_(topic),sourceType_(src),msgType_(Type){
msg = messages::header::Message();
if(msg.IsInitialized())
{
msg.set_sourceid(deviceId);
msg.set_topic(topic);
msg.set_sourcetype(sourceType_);
msg.set_msgtype(msgType_);
}
}
std::string Message::getPayloadString(){
return payloadString_;
}
void Message::addPayLoad(std::shared_ptr<google::protobuf::Any> payload){
payload_ = payload;
LOG_S(INFO)<< "pack any size in message class "<<payload_->ByteSizeLong();
msg.add_payload()->CopyFrom(*payload_);
LOG_S(INFO)<< "pack any size in message class "<<payload_->ByteSizeLong();
}
std::string Message::serialize(){
std::string serializedMessage;
LOG_S(INFO)<<msg.ByteSizeLong();
if (msg.IsInitialized()) {
serializedMessage = msg.SerializeAsString();
}
return serializedMessage;
}
}