forked from aeraki-mesh/meta-protocol-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol_constants.h
99 lines (78 loc) · 3.04 KB
/
protocol_constants.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#pragma once
#include "source/common/common/assert.h"
#include "source/common/common/fmt.h"
#include "source/common/singleton/const_singleton.h"
#include "src/application_protocols/dubbo/message.h"
#include "absl/container/node_hash_map.h"
namespace Envoy {
namespace Extensions {
namespace NetworkFilters {
namespace MetaProtocolProxy {
namespace Dubbo {
/**
* Names of available Protocol implementations.
*/
class ProtocolNameValues {
public:
struct ProtocolTypeHash {
template <typename T> std::size_t operator()(T t) const { return static_cast<std::size_t>(t); }
};
using ProtocolTypeNameMap = absl::node_hash_map<ProtocolType, std::string, ProtocolTypeHash>;
const ProtocolTypeNameMap protocolTypeNameMap = {
{ProtocolType::Dubbo, "dubbo"},
};
const std::string& fromType(ProtocolType type) const {
const auto& itor = protocolTypeNameMap.find(type);
ASSERT(itor != protocolTypeNameMap.end());
return itor->second;
}
};
using ProtocolNames = ConstSingleton<ProtocolNameValues>;
/**
* Names of available serializer implementations.
*/
class SerializerNameValues {
public:
struct SerializationTypeHash {
template <typename T> std::size_t operator()(T t) const { return static_cast<std::size_t>(t); }
};
using SerializerTypeNameMap =
absl::node_hash_map<SerializationType, std::string, SerializationTypeHash>;
const SerializerTypeNameMap serializerTypeNameMap = {
{SerializationType::Hessian2, "hessian2"},
};
const std::string& fromType(SerializationType type) const {
const auto& itor = serializerTypeNameMap.find(type);
ASSERT(itor != serializerTypeNameMap.end());
return itor->second;
}
};
using SerializerNames = ConstSingleton<SerializerNameValues>;
class ProtocolSerializerNameValues {
public:
inline uint8_t generateKey(ProtocolType protocol_type,
SerializationType serialization_type) const {
return static_cast<uint8_t>(serialization_type) ^ static_cast<uint8_t>(protocol_type);
}
inline std::string generateValue(ProtocolType protocol_type,
SerializationType serialization_type) const {
return fmt::format("{}.{}", ProtocolNames::get().fromType(protocol_type),
SerializerNames::get().fromType(serialization_type));
}
#define GENERATE_PAIR(X, Y) generateKey(X, Y), generateValue(X, Y)
using ProtocolSerializerTypeNameMap = absl::node_hash_map<uint8_t, std::string>;
const ProtocolSerializerTypeNameMap protocolSerializerTypeNameMap = {
{GENERATE_PAIR(ProtocolType::Dubbo, SerializationType::Hessian2)},
};
const std::string& fromType(ProtocolType protocol_type, SerializationType type) const {
const auto& itor = protocolSerializerTypeNameMap.find(generateKey(protocol_type, type));
ASSERT(itor != protocolSerializerTypeNameMap.end());
return itor->second;
}
};
using ProtocolSerializerNames = ConstSingleton<ProtocolSerializerNameValues>;
} // namespace Dubbo
} // namespace MetaProtocolProxy
} // namespace NetworkFilters
} // namespace Extensions
} // namespace Envoy