lichao
2021-03-24 6f9521a6dca494a9f9644d1ccacdee23744dc0e5
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
52
53
54
55
56
57
/*
 * =====================================================================================
 *
 *       Filename:  msg.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2021年03月24日 16时49分20秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Li Chao (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef MSG_5BILLZET
#define MSG_5BILLZET
 
#include <stdint.h>
#include <boost/interprocess/offset_ptr.hpp>
 
namespace bhome_shm {
 
using namespace boost::interprocess;
 
// safe to be stored in shared memory.
// message format: header(meta) + body(data).
enum MsgType {
    kMsgTypeNull = 0,
    kMsgTypeNormal = 1,
    kMsgTypeMaxValue
};
 
const uint32_t kMsgMetaTag = 0xf1e2d3c4;
 
struct MsgMetaV1 {
    uint16_t self_size_ = sizeof(MsgMetaV1); // sizeof(*this)
    uint16_t type_ = kMsgTypeNormal; // msg type.
    uint32_t tag_ = kMsgMetaTag;
    uint32_t data_size_ = 0;
    unsigned char src_id_[16] = {0};
    // more fields add at end, must not change
 
    MsgMetaV1(){}
    bool Parse(const void *p);
    void Pack(void *p);
};
 
typedef offset_ptr<void> Msg;
 
} // namespace bhome_shm
 
 
 
#endif // end of include guard: MSG_5BILLZET