-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProtocol.h
61 lines (49 loc) · 1.35 KB
/
Protocol.h
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
#pragma once
#include <google/protobuf/message.h>
#include <google/protobuf/compiler/importer.h>
#include <google/protobuf/compiler/parser.h>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/dynamic_message.h>
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/io/tokenizer.h>
#include <unordered_map>
#include <string>
#include <iostream>
#include <functional>
#include "P_Header.h"
namespace Adoter {
namespace pb = google::protobuf;
/*
* 类功能:
*
* 1.自动注册(.proto)文件中的所有协议;
*
* 2.代码风格倾向于使用C++11新特性,其他功能补充使用Boost开源库;
*
* 说明:此处的协议数据指谷歌ProtocolBuffer内容中的Message,用于区分消息队列中的Message,所以命名如此.
*
* */
class ProtocolManager : public std::enable_shared_from_this<ProtocolManager>
{
private:
bool _parse_sucess;
std::string _proto_file_path;
std::unordered_map<int32_t, pb::Message*> _messages;
public:
ProtocolManager();
static ProtocolManager& Instance()
{
static ProtocolManager _instance;
return _instance;
}
pb::Message* GetMessage(int32_t message_type)
{
auto it = _messages.find(message_type);
if (it == _messages.end()) return nullptr;
return it->second;
}
//加载协议
bool Load();
};
#define ProtocolInstance ProtocolManager::Instance()
}