MCPcopy Create free account
hub / github.com/apache/brpc / ParseNsheadMeta

Method ParseNsheadMeta

src/brpc/policy/ubrpc2pb_protocol.cpp:47–169  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45static const unsigned int UBRPC_NSHEAD_VERSION = 1000;
46
47void UbrpcAdaptor::ParseNsheadMeta(
48 const Server&, const NsheadMessage& request, Controller* cntl,
49 NsheadMeta* out_meta) const {
50 butil::IOBufAsZeroCopyInputStream zc_stream(request.body);
51 mcpack2pb::InputStream stream(&zc_stream);
52 if (!::mcpack2pb::unbox(&stream)) {
53 cntl->SetFailed(EREQUEST, "Request is not a compack/mcpack2 object");
54 return;
55 }
56 mcpack2pb::ObjectIterator it1(&stream, request.body.size() - stream.popped_bytes());
57 bool found_content = false;
58 for (; it1 != NULL; ++it1) {
59 if (it1->name == "content") {
60 found_content = true;
61 break;
62 }
63 }
64 if (!found_content) {
65 cntl->SetFailed(EREQUEST, "Fail to find request.content");
66 return;
67 }
68 if (it1->value.type() != mcpack2pb::FIELD_ARRAY) {
69 cntl->SetFailed(EREQUEST, "Expect request.content to be array, "
70 "actually %s", mcpack2pb::type2str(it1->value.type()));
71 return;
72 }
73
74 mcpack2pb::ArrayIterator it2(it1->value);
75 if (it2 == NULL) {
76 cntl->SetFailed(EREQUEST, "Fail to parse request.content as array");
77 return;
78 }
79 std::string service_name;
80 std::string method_name;
81 bool has_params = false;
82 size_t user_req_offset = 0;
83 size_t user_req_size = 0;
84 for (mcpack2pb::ObjectIterator it3(*it2); it3 != NULL; ++it3) {
85 if (it3->name == "service_name") {
86 if (it3->value.type() != mcpack2pb::FIELD_STRING) {
87 cntl->SetFailed(EREQUEST, "Expect request.content[0].service_name"
88 " to be string, actually %s",
89 mcpack2pb::type2str(it3->value.type()));
90 return;
91 }
92 it3->value.as_string(&service_name, "request.content[0].service_name");
93 } else if (it3->name == "method") {
94 if (it3->value.type() != mcpack2pb::FIELD_STRING) {
95 cntl->SetFailed(EREQUEST, "Expect request.content[0].method"
96 " to be string, actually %s",
97 mcpack2pb::type2str(it3->value.type()));
98 return;
99 }
100 it3->value.as_string(&method_name, "request.content[0].method");
101 } else if (it3->name == "id") {
102 if (!mcpack2pb::is_primitive(it3->value.type()) ||
103 !mcpack2pb::is_integral((mcpack2pb::PrimitiveFieldType)it3->value.type())) {
104 cntl->SetFailed(ERESPONSE, "request.content[0].id must be "

Callers

nothing calls this directly

Calls 15

unboxFunction · 0.85
is_primitiveFunction · 0.85
set_correlation_idMethod · 0.80
field_countMethod · 0.80
popnMethod · 0.80
type2strFunction · 0.50
is_integralClass · 0.50
SetFailedMethod · 0.45
sizeMethod · 0.45
popped_bytesMethod · 0.45
typeMethod · 0.45
as_stringMethod · 0.45

Tested by

no test coverage detected