| 216 | } |
| 217 | |
| 218 | static bool SerializeResponse(const google::protobuf::Message& res, |
| 219 | Controller& cntl, butil::IOBuf& buf) { |
| 220 | if (res.GetDescriptor() == SerializedResponse::descriptor()) { |
| 221 | buf.swap(((SerializedResponse&)res).serialized_data()); |
| 222 | return true; |
| 223 | } |
| 224 | |
| 225 | if (!res.IsInitialized()) { |
| 226 | cntl.SetFailed(ERESPONSE, "Missing required fields in response: %s", |
| 227 | res.InitializationErrorString().c_str()); |
| 228 | return false; |
| 229 | } |
| 230 | |
| 231 | ContentType content_type = cntl.response_content_type(); |
| 232 | CompressType compress_type = cntl.response_compress_type(); |
| 233 | ChecksumType checksum_type = cntl.response_checksum_type(); |
| 234 | if (!SerializeRpcMessage(res, cntl, content_type, compress_type, |
| 235 | checksum_type, &buf)) { |
| 236 | cntl.SetFailed(ERESPONSE, |
| 237 | "Fail to serialize response=%s, " |
| 238 | "ContentType=%s, CompressType=%s, ChecksumType=%s", |
| 239 | butil::EnsureString(res.GetDescriptor()->full_name()).c_str(), |
| 240 | ContentTypeToCStr(content_type), |
| 241 | CompressTypeToCStr(compress_type), |
| 242 | ChecksumTypeToCStr(checksum_type)); |
| 243 | return false; |
| 244 | } |
| 245 | return true; |
| 246 | } |
| 247 | |
| 248 | namespace { |
| 249 | struct BaiduProxyPBMessages : public RpcPBMessages { |
no test coverage detected