lichao
2021-04-13 7f307880a58012077833061b5ff18ba63c1a2269
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
 * =====================================================================================
 *
 *       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;
}