Files
whisper-com/src/WHISPER/Messages/Message.cpp
Henry Winkel 1ae59dbf28 revert 8ce7718201
revert FIX: fixed message class to that only one any message can be stored; deleted track class
2022-12-21 13:06:34 +00:00

74 lines
1.5 KiB
C++

#include <WHISPER/Messages/Message.hpp>
#include <memory>
namespace WHISPER {
Message::Message(std::string stringMessage)
{
msg = messages::header::Message();
try {
msg.ParseFromString(stringMessage);
deviceId_ = msg.sourceid();
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, MsgTopics 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_);
}
deviceId_ = deviceId;
topic_ = topic;
sourceType_ = src;
msgType_ = Type;
}
std::string Message::getPayloadString(){
return payloadString_;
}
void Message::addPayLoad(std::shared_ptr<google::protobuf::Any> payload){
payload_ = payload;
msg.clear_payload();
msg.add_payload()->CopyFrom(*payload_);
}
std::string Message::serialize(){
std::string serializedMessage;
if (msg.IsInitialized()) {
serializedMessage = msg.SerializeAsString();
}
return serializedMessage;
}
}