| 113 | } |
| 114 | |
| 115 | void 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 | |
| 152 | void ProcessPublicPbrpcResponse(InputMessageBase* msg_base) { |
| 153 | const int64_t start_parse_us = butil::cpuwide_time_us(); |
nothing calls this directly
no test coverage detected