client_proto_head.h
1.69 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
//客户端协议的包头
#pragma once
#include <common.h>
#include <proto_header.h>
//////////////////////////////////////////////////////////////////////////
//协议包头格式
struct cli_proto_head_t : public el::lib_proto_head_base_t{
PROTO_LEN length; //all of pack
uint32_t seq;
CMD_ID cmd;
uint32_t result;
USER_ID id;
static const uint32_t PROTO_HEAD_LEN = 24;
virtual uint32_t get_proto_head_len(){
return cli_proto_head_t::PROTO_HEAD_LEN;
}
virtual void unpack(const void* data){
cli_recv_data_t in(data);
in>>this->length
>>this->seq
>>this->cmd
>>this->result
>>this->id;
}
virtual uint32_t len_offset(){
return 0;
}
virtual void* get_len_pointer(){
return &this->length;
}
virtual uint32_t get_all_len(){
return this->length;
}
virtual uint32_t get_body_len(){
return this->length - cli_proto_head_t::PROTO_HEAD_LEN;
}
virtual uint32_t get_cmd(){
return this->cmd;
}
virtual void set_len(uint32_t len){
this->length = (PROTO_LEN)len;
}
virtual bool is_all_len(){
return true;
}
virtual void* get_data_pointer(){
return &this->length;
}
//////////////////////////////////////////////////////////////////////////
cli_proto_head_t(){
this->clear();
}
cli_proto_head_t(CMD_ID cmd){
this->clear();
this->cmd = cmd;
}
void clear(){
this->length= 0;
this->seq = 0;
this->cmd = 0;
this->result = 0;
this->id = 0;
}
static inline uint32_t get_cmd_pos(){
return sizeof(PROTO_LEN)+sizeof(uint32_t);
}
//获取包头长度的最小包长
static inline uint32_t get_pkg_len_min_len(){
return cli_proto_head_t::PROTO_HEAD_LEN;
}
//获取包头长度的开始位置
static inline uint32_t get_pkg_len_pos(){
return 0;
}
};