FIX: fixed message class to that only one any message can be stored; deleted track class
This commit is contained in:
@@ -1,74 +0,0 @@
|
||||
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user