Class CompressionCodecs

java.lang.Object
io.deephaven.grpc.compression.CompressionCodecs

public final class CompressionCodecs extends Object
The compression types that Deephaven supports for gRPC messages, named as in gRPC's grpc-encoding and grpc-accept-encoding headers; their gRPC registries; and parsers for compression type lists and a client's grpc-accept-encoding. The supported types are the ones that the CompressionCodecProviders on the classpath supply: zstd, gzip, snappy and deflate, whose providers this module includes, plus every type that a deployment's own provider adds.
  • Field Details

    • SUPPORTED

      public static final List<String> SUPPORTED
      The name of every supported compression type, excluding identity, sorted by name. The providers this module includes supply:
      • deflate: the algorithm of gzip in the zlib format, which compresses to the same size at the same speed and decompresses slightly slower. Clients built on gRPC Core, such as the Python, C++ and R clients, can decode it and gzip, but no other type this module includes.
      • gzip: compresses slightly smaller than zstd but much more slowly. Most gRPC clients can decode it.
      • snappy: the fastest of these types, but the one that saves the least.
      • zstd: Zstandard, which compresses nearly as well as gzip, and many times faster.
      Every other CompressionCodecProvider on the classpath adds its type, or replaces the built-in type of the same name.
  • Method Details

    • compressorRegistry

      public static io.grpc.CompressorRegistry compressorRegistry()
      Returns:
      a registry holding a compressor for every supported encoding, plus identity
    • compressorRegistry

      public static io.grpc.CompressorRegistry compressorRegistry(@NotNull @NotNull Collection<String> types)
      Parameters:
      types - the encodings to register; each must be supported
      Returns:
      a registry holding a compressor for each of types, plus identity
    • decompressorRegistry

      public static io.grpc.DecompressorRegistry decompressorRegistry(@NotNull @NotNull Collection<String> advertised)
      Builds a registry that can decode every supported encoding, but advertises only advertised in the grpc-accept-encoding header.
      Parameters:
      advertised - the encodings to advertise; each must be supported
      Returns:
      the registry
    • decompressorRegistry

      public static io.grpc.DecompressorRegistry decompressorRegistry(@NotNull @NotNull Collection<String> types, @NotNull @NotNull Collection<String> advertised)
      Builds a registry that can decode each of types, but advertises only those also in advertised in the grpc-accept-encoding header.
      Parameters:
      types - the encodings to decode; each must be supported
      advertised - the encodings to advertise; each must be supported
      Returns:
      the registry
    • codec

      public static io.grpc.Codec codec(@NotNull @NotNull String name)
      Parameters:
      name - the name of a compression type; case and surrounding whitespace are ignored
      Returns:
      the codec for name, the one that compressorRegistry() and decompressorRegistry(Collection) register
      Throws:
      IllegalArgumentException - if name is not supported
    • parseList

      public static List<String> parseList(@Nullable @Nullable String list)
      Parses an ordered, comma-separated list of encoding names, such as "zstd, snappy, gzip". Names are trimmed and lower-cased, blank entries are skipped, and repeats keep their first position.
      Parameters:
      list - the list to parse; null or blank yields an empty list
      Returns:
      the encodings, in order of preference
      Throws:
      IllegalArgumentException - if a name is not supported
    • parseAcceptEncoding

      public static Set<String> parseAcceptEncoding(@Nullable @Nullable String header)
      Parses the value of a grpc-accept-encoding header. Unlike parseList(String), unknown names are kept; they simply never match.
      Parameters:
      header - the header value; null yields an empty set
      Returns:
      the lower-cased encoding names
    • checkSupported

      public static String checkSupported(@NotNull @NotNull String name)
      Parameters:
      name - the name of a compression type; case and surrounding whitespace are ignored
      Returns:
      name, trimmed and lower-cased
      Throws:
      IllegalArgumentException - if name is not supported