forked from aeraki-mesh/meta-protocol-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hessian_utils.cc
72 lines (62 loc) · 1.52 KB
/
hessian_utils.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
#include "src/application_protocols/dubbo/hessian_utils.h"
namespace Envoy {
namespace Extensions {
namespace NetworkFilters {
namespace MetaProtocolProxy {
namespace Dubbo {
// Check
// https://github.com/apache/dubbo/blob/master/dubbo-common/src/main/java/org/apache/dubbo/common/utils/ReflectUtils.java
// for details of parameters type.
uint32_t HessianUtils::getParametersNumber(const std::string& parameters_type) {
if (parameters_type.empty()) {
return 0;
}
uint32_t count = 0;
bool next = false;
for (auto ch : parameters_type) {
if (ch == '[') {
// Is array.
continue;
}
if (next && ch != ';') {
// Is Object.
continue;
}
switch (ch) {
case 'V':
case 'Z':
case 'B':
case 'C':
case 'D':
case 'F':
case 'I':
case 'J':
case 'S':
count++;
break;
case 'L':
// Start of Object.
count++;
next = true;
break;
case ';':
// End of Object.
next = false;
break;
default:
break;
}
}
return count;
}
void BufferWriter::rawWrite(const void* data, uint64_t size) { buffer_.add(data, size); }
void BufferWriter::rawWrite(absl::string_view data) { buffer_.add(data); }
void BufferReader::rawReadNBytes(void* data, size_t len, size_t peek_offset) {
ASSERT(byteAvailable() - peek_offset >= len);
buffer_.copyOut(offset() + peek_offset, len, data);
}
} // namespace Dubbo
} // namespace MetaProtocolProxy
} // namespace NetworkFilters
} // namespace Extensions
} // namespace Envoy