Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/compression/decompressor/decompressor.h" 4 : #include "envoy/stats/scope.h" 5 : #include "envoy/stats/stats_macros.h" 6 : 7 : #include "source/extensions/compression/brotli/common/base.h" 8 : 9 : #include "brotli/decode.h" 10 : 11 : namespace Envoy { 12 : namespace Extensions { 13 : namespace Compression { 14 : namespace Brotli { 15 : namespace Decompressor { 16 : 17 : /** 18 : * All brotli decompressor stats. @see stats_macros.h 19 : */ 20 0 : #define ALL_BROTLI_DECOMPRESSOR_STATS(COUNTER) COUNTER(brotli_error) 21 : 22 : /** 23 : * Struct definition for brotli decompressor stats. @see stats_macros.h 24 : */ 25 : struct BrotliDecompressorStats { 26 : ALL_BROTLI_DECOMPRESSOR_STATS(GENERATE_COUNTER_STRUCT) 27 : }; 28 : 29 : /** 30 : * Implementation of decompressor's interface. 31 : */ 32 : class BrotliDecompressorImpl : public Envoy::Compression::Decompressor::Decompressor, NonCopyable { 33 : public: 34 : /** 35 : * Constructor. 36 : * @param chunk_size amount of memory reserved for the decompressor output. 37 : * @param disable_ring_buffer_reallocation if true disables "canny" ring buffer allocation 38 : * strategy. Ring buffer is allocated according to window size, despite the real size of the 39 : * content. 40 : */ 41 : BrotliDecompressorImpl(Stats::Scope& scope, const std::string& stats_prefix, 42 : const uint32_t chunk_size, bool disable_ring_buffer_reallocation); 43 : 44 : // Envoy::Compression::Decompressor::Decompressor 45 : void decompress(const Buffer::Instance& input_buffer, Buffer::Instance& output_buffer) override; 46 : 47 : private: 48 0 : static BrotliDecompressorStats generateStats(const std::string& prefix, Stats::Scope& scope) { 49 0 : return BrotliDecompressorStats{ 50 0 : ALL_BROTLI_DECOMPRESSOR_STATS(POOL_COUNTER_PREFIX(scope, prefix))}; 51 0 : } 52 : 53 : bool process(Common::BrotliContext& ctx, Buffer::Instance& output_buffer); 54 : 55 : const uint32_t chunk_size_; 56 : std::unique_ptr<BrotliDecoderState, decltype(&BrotliDecoderDestroyInstance)> state_; 57 : const BrotliDecompressorStats stats_; 58 : }; 59 : 60 : } // namespace Decompressor 61 : } // namespace Brotli 62 : } // namespace Compression 63 : } // namespace Extensions 64 : } // namespace Envoy