| 171 | } |
| 172 | |
| 173 | Result<CompressResult> Compress(int64_t input_len, const uint8_t* input, |
| 174 | int64_t output_len, uint8_t* output) override { |
| 175 | auto src = input; |
| 176 | auto dst = output; |
| 177 | auto src_size = static_cast<size_t>(input_len); |
| 178 | auto dst_capacity = static_cast<size_t>(output_len); |
| 179 | size_t ret; |
| 180 | int64_t bytes_written = 0; |
| 181 | |
| 182 | BEGIN_COMPRESS(dst, dst_capacity, (CompressResult{0, 0})); |
| 183 | |
| 184 | if (dst_capacity < LZ4F_compressBound(src_size, &prefs_)) { |
| 185 | // Output too small to compress into |
| 186 | return CompressResult{0, bytes_written}; |
| 187 | } |
| 188 | ret = LZ4F_compressUpdate(ctx_, dst, dst_capacity, src, src_size, |
| 189 | nullptr /* options */); |
| 190 | if (LZ4F_isError(ret)) { |
| 191 | return LZ4Error(ret, "LZ4 compress update failed: "); |
| 192 | } |
| 193 | bytes_written += static_cast<int64_t>(ret); |
| 194 | DCHECK_LE(bytes_written, output_len); |
| 195 | return CompressResult{input_len, bytes_written}; |
| 196 | } |
| 197 | |
| 198 | Result<FlushResult> Flush(int64_t output_len, uint8_t* output) override { |
| 199 | auto dst = output; |
no test coverage detected