/* * ===================================================================================== * * 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 #include namespace { std::string RandId() { boost::uuids::uuid id = boost::uuids::random_generator()(); return std::string((char *) &id, sizeof(id)); } } // namespace std::string NewMsgId() { return RandId(); } BHMsgHead InitMsgHead(const MsgType type, const std::string &proc_id, const uint64_t ssn_id) { return InitMsgHead(type, proc_id, ssn_id, RandId()); } BHMsgHead InitMsgHead(const MsgType type, const std::string &proc_id, const uint64_t ssn_id, const std::string &msgid) { BHMsgHead msg; msg.set_msg_id(msgid); msg.set_type(type); msg.set_proc_id(proc_id); msg.set_ssn_id(ssn_id); msg.set_timestamp(NowSec()); return msg; } bool IsMsgExpired(const BHMsgHead &head) { return NowSec() > head.timestamp() + 10; }