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

Method SerializeResponseToIOBuf

src/brpc/policy/public_pbrpc_protocol.cpp:115–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115void PublicPbrpcServiceAdaptor::SerializeResponseToIOBuf(
116 const NsheadMeta& meta, Controller* cntl,
117 const google::protobuf::Message* pb_res, NsheadMessage* raw_res) const {
118 PublicPbrpcResponse whole_res;
119 ResponseHead* head = whole_res.mutable_responsehead();
120 ResponseBody* body = whole_res.add_responsebody();
121
122 head->set_from_host(butil::ip2str(butil::my_ip()).c_str());
123 body->set_version(meta.user_string());
124 body->set_id(meta.correlation_id());
125 if (cntl->Failed()) {
126 head->set_code(cntl->ErrorCode());
127 head->set_text(cntl->ErrorText());
128 } else {
129 head->set_code(0);
130 head->set_text(SUCCESS_TEXT);
131 std::string* response_str = body->mutable_serialized_response();
132 if (!pb_res->SerializeToString(response_str)) {
133 cntl->CloseConnection("Close connection due to failure of "
134 "serializing user's response");
135 return;
136 }
137 if (cntl->response_compress_type() == COMPRESS_TYPE_SNAPPY) {
138 std::string tmp;
139 butil::snappy::Compress(response_str->data(), response_str->size(), &tmp);
140 response_str->swap(tmp);
141 head->set_compress_type(COMPRESS_TYPE);
142 }
143 }
144 butil::IOBufAsZeroCopyOutputStream wrapper(&raw_res->body);
145 if (!whole_res.SerializeToZeroCopyStream(&wrapper)) {
146 cntl->CloseConnection("Close connection due to failure of "
147 "serializing the whole response");
148 return;
149 }
150}
151
152void ProcessPublicPbrpcResponse(InputMessageBase* msg_base) {
153 const int64_t start_parse_us = butil::cpuwide_time_us();

Callers

nothing calls this directly

Calls 14

ip2strFunction · 0.85
my_ipFunction · 0.85
CompressFunction · 0.85
correlation_idMethod · 0.80
ErrorCodeMethod · 0.80
ErrorTextMethod · 0.80
CloseConnectionMethod · 0.80
c_strMethod · 0.45
set_versionMethod · 0.45
FailedMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected