syntax = "proto3";

package envoy.extensions.compression.gzip.compressor.v3;

import "google/protobuf/wrappers.proto";

import "udpa/annotations/status.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.extensions.compression.gzip.compressor.v3";
option java_outer_classname = "GzipProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/compression/gzip/compressor/v3;compressorv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: Gzip Compressor]
// [#extension: envoy.compression.gzip.compressor]

// [#next-free-field: 6]
message Gzip {
  // All the values of this enumeration translate directly to zlib's compression strategies.
  // For more information about each strategy, please refer to the
  // `zlib manual <https://www.zlib.net/manual.html>`_.
  enum CompressionStrategy {
    // Default compression strategy.
    DEFAULT_STRATEGY = 0;

    // Filtered compression strategy, designed for data produced by a filter or predictor.
    FILTERED = 1;

    // Huffman-only compression strategy, which uses Huffman encoding only.
    HUFFMAN_ONLY = 2;

    // Run-length encoding (RLE) compression strategy, designed for image data.
    RLE = 3;

    // Fixed compression strategy, which prevents the use of dynamic Huffman codes.
    FIXED = 4;
  }

  // Compression level values for zlib. Higher levels provide better compression at the cost of
  // increased latency and CPU usage.
  enum CompressionLevel {
    option allow_alias = true;

    // Default compression level, equivalent to ``COMPRESSION_LEVEL_6``.
    DEFAULT_COMPRESSION = 0;

    // Fastest compression with minimal compression ratio, equivalent to ``COMPRESSION_LEVEL_1``.
    BEST_SPEED = 1;

    // Compression level 1 (fastest).
    COMPRESSION_LEVEL_1 = 1;

    // Compression level 2.
    COMPRESSION_LEVEL_2 = 2;

    // Compression level 3.
    COMPRESSION_LEVEL_3 = 3;

    // Compression level 4.
    COMPRESSION_LEVEL_4 = 4;

    // Compression level 5.
    COMPRESSION_LEVEL_5 = 5;

    // Compression level 6.
    COMPRESSION_LEVEL_6 = 6;

    // Compression level 7.
    COMPRESSION_LEVEL_7 = 7;

    // Compression level 8.
    COMPRESSION_LEVEL_8 = 8;

    // Compression level 9 (best compression).
    COMPRESSION_LEVEL_9 = 9;

    // Best compression ratio with highest latency, equivalent to ``COMPRESSION_LEVEL_9``.
    BEST_COMPRESSION = 9;
  }

  // Value from 1 to 9 that controls the amount of internal memory used by zlib. Higher values
  // use more memory, but are faster and produce better compression results.
  //
  // Defaults to ``5``.
  google.protobuf.UInt32Value memory_level = 1 [(validate.rules).uint32 = {lte: 9 gte: 1}];

  // A value used for selecting the zlib compression level. This setting will affect speed and
  // amount of compression applied to the content. ``BEST_COMPRESSION`` provides higher compression
  // at the cost of higher latency and is equal to ``COMPRESSION_LEVEL_9``. ``BEST_SPEED`` provides
  // lower compression with minimum impact on response time, the same as ``COMPRESSION_LEVEL_1``.
  // ``DEFAULT_COMPRESSION`` provides an optimal result between speed and compression. According
  // to zlib's manual, this level gives the same result as ``COMPRESSION_LEVEL_6``.
  //
  // Defaults to ``DEFAULT_COMPRESSION``.
  CompressionLevel compression_level = 2 [(validate.rules).enum = {defined_only: true}];

  // A value used for selecting the zlib compression strategy which is directly related to the
  // characteristics of the content. Most of the time ``DEFAULT_STRATEGY`` will be the best choice,
  // though there are situations when changing this parameter might produce better results. For
  // example, run-length encoding (RLE) is typically used when the content is known for having
  // sequences in which the same data occurs many consecutive times. For more information about
  // each strategy, please refer to the `zlib manual <https://www.zlib.net/manual.html>`_.
  //
  // Defaults to ``DEFAULT_STRATEGY``.
  CompressionStrategy compression_strategy = 3 [(validate.rules).enum = {defined_only: true}];

  // Value from 9 to 15 that represents the base two logarithmic of the compressor's window size.
  // Larger window results in better compression at the expense of memory usage. For more details
  // about this parameter, please refer to the
  // `zlib manual <https://www.zlib.net/manual.html>`_ for ``deflateInit2``.
  //
  // Defaults to ``12``, which will produce a 4096 bytes window.
  google.protobuf.UInt32Value window_bits = 4 [(validate.rules).uint32 = {lte: 15 gte: 9}];

  // Value for zlib's next output buffer. See the
  // `zlib manual <https://www.zlib.net/manual.html>`_ for more details. Also see
  // `envoy#8448 <https://github.com/envoyproxy/envoy/issues/8448>`_ for context on this filter's
  // performance.
  //
  // Defaults to ``4096``.
  google.protobuf.UInt32Value chunk_size = 5 [(validate.rules).uint32 = {lte: 65536 gte: 4096}];
}
