| 218 | } |
| 219 | |
| 220 | Result<EndResult> End(int64_t output_len, uint8_t* output) override { |
| 221 | auto dst = output; |
| 222 | auto dst_capacity = static_cast<size_t>(output_len); |
| 223 | size_t ret; |
| 224 | int64_t bytes_written = 0; |
| 225 | |
| 226 | BEGIN_COMPRESS(dst, dst_capacity, (EndResult{0, true})); |
| 227 | |
| 228 | if (dst_capacity < LZ4F_compressBound(0, &prefs_)) { |
| 229 | // Output too small to end frame into |
| 230 | return EndResult{bytes_written, true}; |
| 231 | } |
| 232 | |
| 233 | ret = LZ4F_compressEnd(ctx_, dst, dst_capacity, nullptr /* options */); |
| 234 | if (LZ4F_isError(ret)) { |
| 235 | return LZ4Error(ret, "LZ4 end failed: "); |
| 236 | } |
| 237 | bytes_written += static_cast<int64_t>(ret); |
| 238 | DCHECK_LE(bytes_written, output_len); |
| 239 | return EndResult{bytes_written, false}; |
| 240 | } |
| 241 | |
| 242 | #undef BEGIN_COMPRESS |
| 243 | |