| 243 | } |
| 244 | |
| 245 | Status CompressStringToBuffer(const string& content, |
| 246 | vector<uint8_t>& output) { |
| 247 | // Declare the compressor |
| 248 | scoped_ptr<Codec> compressor; |
| 249 | Codec::CodecInfo codec_info(THdfsCompression::GZIP, Z_BEST_SPEED); |
| 250 | LOG_AND_RETURN_IF_ERROR(Codec::CreateCompressor(NULL, false, codec_info, &compressor)); |
| 251 | auto compressor_cleanup = MakeScopeExitTrigger([&compressor]() { |
| 252 | compressor->Close(); |
| 253 | }); |
| 254 | // Interpret the data in the required form, do not reallocate |
| 255 | uint8_t* content_buffer = reinterpret_cast<uint8_t*>(const_cast<char*>( |
| 256 | content.data())); |
| 257 | // Allocate the necessary space |
| 258 | int64_t compressed_length = compressor->MaxOutputLen(content.size(), content_buffer); |
| 259 | output.resize(compressed_length); |
| 260 | // Transform the space into necessary form |
| 261 | uint8_t* compressed_buffer = output.data(); |
| 262 | LOG_AND_RETURN_IF_ERROR(compressor->ProcessBlock(true, content.size(), content_buffer, |
| 263 | &compressed_length, &compressed_buffer)); |
| 264 | output.resize(compressed_length); |
| 265 | return Status::OK(); |
| 266 | } |
| 267 | |
| 268 | // Return the address of the remote user from the squeasel request info. |
| 269 | kudu::Sockaddr GetRemoteAddress(const struct sq_request_info* req) { |
no test coverage detected