Line data Source code
1 : #include "source/extensions/compression/brotli/common/base.h" 2 : 3 : namespace Envoy { 4 : namespace Extensions { 5 : namespace Compression { 6 : namespace Brotli { 7 : namespace Common { 8 : 9 : BrotliContext::BrotliContext(uint32_t chunk_size, uint32_t max_output_size) 10 : : max_output_size_{max_output_size}, chunk_size_{chunk_size}, 11 : chunk_ptr_{std::make_unique<uint8_t[]>(chunk_size)}, next_out_{chunk_ptr_.get()}, 12 0 : avail_out_{chunk_size} {} 13 : 14 0 : void BrotliContext::updateOutput(Buffer::Instance& output_buffer) { 15 0 : if (avail_out_ == 0) { 16 0 : output_buffer.add(static_cast<void*>(chunk_ptr_.get()), chunk_size_); 17 0 : resetOut(); 18 0 : } 19 0 : } 20 : 21 0 : void BrotliContext::finalizeOutput(Buffer::Instance& output_buffer) { 22 0 : const size_t n_output = chunk_size_ - avail_out_; 23 0 : if (n_output > 0) { 24 0 : output_buffer.add(static_cast<void*>(chunk_ptr_.get()), n_output); 25 0 : } 26 0 : } 27 : 28 0 : void BrotliContext::resetOut() { 29 0 : avail_out_ = chunk_size_; 30 0 : next_out_ = chunk_ptr_.get(); 31 0 : } 32 : 33 : } // namespace Common 34 : } // namespace Brotli 35 : } // namespace Compression 36 : } // namespace Extensions 37 : } // namespace Envoy