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
2823
    : max_output_size_{max_output_size}, chunk_size_{chunk_size},
11
2823
      chunk_ptr_{std::make_unique<uint8_t[]>(chunk_size)}, next_out_{chunk_ptr_.get()},
12
2823
      avail_out_{chunk_size} {}
13

            
14
35853
void BrotliContext::updateOutput(Buffer::Instance& output_buffer) {
15
35853
  if (avail_out_ == 0) {
16
30720
    output_buffer.add(static_cast<void*>(chunk_ptr_.get()), chunk_size_);
17
30720
    resetOut();
18
30720
  }
19
35853
}
20

            
21
2823
void BrotliContext::finalizeOutput(Buffer::Instance& output_buffer) {
22
2823
  const size_t n_output = chunk_size_ - avail_out_;
23
2823
  if (n_output > 0) {
24
2819
    output_buffer.add(static_cast<void*>(chunk_ptr_.get()), n_output);
25
2819
  }
26
2823
}
27

            
28
30720
void BrotliContext::resetOut() {
29
30720
  avail_out_ = chunk_size_;
30
30720
  next_out_ = chunk_ptr_.get();
31
30720
}
32

            
33
} // namespace Common
34
} // namespace Brotli
35
} // namespace Compression
36
} // namespace Extensions
37
} // namespace Envoy