/*
|
* =====================================================================================
|
*
|
* Filename: proto.cpp
|
*
|
* Description:
|
*
|
* Version: 1.0
|
* Created: 2021年04月07日 17时04分36秒
|
* Revision: none
|
* Compiler: gcc
|
*
|
* Author: Li Chao (), lichao@aiotlink.com
|
* Organization:
|
*
|
* =====================================================================================
|
*/
|
#include "proto.h"
|
#include <boost/uuid/uuid_generators.hpp>
|
#include <chrono>
|
|
namespace
|
{
|
|
std::string RandId()
|
{
|
boost::uuids::uuid id = boost::uuids::random_generator()();
|
return std::string((char *) &id, sizeof(id));
|
}
|
|
} // namespace
|
|
BHMsgHead InitMsgHead(const MsgType type, const std::string &proc_id)
|
{
|
return InitMsgHead(type, proc_id, RandId());
|
}
|
|
BHMsgHead InitMsgHead(const MsgType type, const std::string &proc_id, const std::string &msgid)
|
{
|
BHMsgHead msg;
|
msg.set_msg_id(msgid);
|
msg.set_type(type);
|
msg.set_proc_id(proc_id);
|
msg.set_timestamp(NowSec());
|
return msg;
|
}
|
|
bool IsMsgExpired(const BHMsgHead &head)
|
{
|
return NowSec() > head.timestamp() + 10;
|
}
|