-
Notifications
You must be signed in to change notification settings - Fork 29
/
message_impl.cc
107 lines (85 loc) · 3.07 KB
/
message_impl.cc
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
100
101
102
103
104
105
106
107
#include "src/application_protocols/dubbo/message_impl.h"
#include "source/common/http/header_map_impl.h"
namespace Envoy {
namespace Extensions {
namespace NetworkFilters {
namespace MetaProtocolProxy {
namespace Dubbo {
RpcInvocationImpl::Attachment::Attachment(MapPtr&& value, size_t offset)
: attachment_(std::move(value)), attachment_offset_(offset) {
headers_ = Http::RequestHeaderMapImpl::create();
ASSERT(attachment_ != nullptr);
ASSERT(attachment_->toMutableUntypedMap().has_value());
for (const auto& pair : *attachment_) {
const auto key = pair.first->toString();
const auto value = pair.second->toString();
if (!key.has_value() || !value.has_value()) {
continue;
}
headers_->addCopy(Http::LowerCaseString(key.value().get()), value.value().get());
}
}
void RpcInvocationImpl::Attachment::insert(const std::string& key, const std::string& value) {
attachment_updated_ = true;
attachment_->emplace(std::make_unique<String>(key), std::make_unique<String>(value));
auto lowcase_key = Http::LowerCaseString(key);
headers_->remove(lowcase_key);
headers_->addCopy(lowcase_key, value);
}
void RpcInvocationImpl::Attachment::remove(const std::string& key) {
ASSERT(attachment_->toMutableUntypedMap().has_value());
attachment_updated_ = true;
attachment_->toMutableUntypedMap().value().get().erase(key);
headers_->remove(Http::LowerCaseString(key));
}
const std::string* RpcInvocationImpl::Attachment::lookup(const std::string& key) const {
ASSERT(attachment_->toMutableUntypedMap().has_value());
auto& map = attachment_->toMutableUntypedMap().value().get();
auto result = map.find(key);
if (result != map.end() && result->second->toString().has_value()) {
return &(result->second->toString().value().get());
}
return nullptr;
}
void RpcInvocationImpl::assignParametersIfNeed() const {
ASSERT(parameters_lazy_callback_ != nullptr);
if (parameters_ == nullptr) {
parameters_ = parameters_lazy_callback_();
}
}
void RpcInvocationImpl::assignAttachmentIfNeed() const {
ASSERT(attachment_lazy_callback_ != nullptr);
if (attachment_ != nullptr) {
return;
}
assignParametersIfNeed();
attachment_ = attachment_lazy_callback_();
if (auto g = attachment_->lookup("group"); g != nullptr) {
const_cast<RpcInvocationImpl*>(this)->group_ = *g;
}
}
const absl::optional<std::string>& RpcInvocationImpl::serviceGroup() const {
assignAttachmentIfNeed();
return group_;
}
RpcInvocationImpl::Attachment& RpcInvocationImpl::attachment() const {
assignAttachmentIfNeed();
return *attachment_;
}
RpcInvocationImpl::AttachmentPtr& RpcInvocationImpl::mutableAttachment() const {
assignAttachmentIfNeed();
return attachment_;
}
const RpcInvocationImpl::Parameters& RpcInvocationImpl::parameters() const {
assignParametersIfNeed();
return *parameters_;
}
RpcInvocationImpl::ParametersPtr& RpcInvocationImpl::mutableParameters() const {
assignParametersIfNeed();
return parameters_;
}
} // namespace Dubbo
} // namespace MetaProtocolProxy
} // namespace NetworkFilters
} // namespace Extensions
} // namespace Envoy