pub enum CompressionAlgorithm {
Zstd,
Lz4,
Gzip,
Deflate,
Snappy,
Identity,
}Expand description
A supported value of the grpc-encoding header.
Variants§
Zstd
Zstandard frames, compressed at level 1.
Lz4
LZ4 frames.
Gzip
RFC 1952 gzip streams.
Deflate
RFC 1950 zlib-wrapped deflate streams.
Snappy
Snappy raw blocks.
Identity
Uncompressed bytes.
Implementations§
Source§impl CompressionAlgorithm
impl CompressionAlgorithm
Sourcepub const fn as_str(self) -> &'static str
pub const fn as_str(self) -> &'static str
The lowercase wire token used in gRPC encoding headers.
Sourcepub fn from_encoding(encoding: &str) -> Result<CompressionAlgorithm, Status>
pub fn from_encoding(encoding: &str) -> Result<CompressionAlgorithm, Status>
Parses an exact, case-sensitive gRPC encoding token.
§Errors
Returns Unimplemented for an unsupported encoding.
Sourcepub fn compress(self, input: &[u8]) -> Result<Vec<u8>, Status>
pub fn compress(self, input: &[u8]) -> Result<Vec<u8>, Status>
Compresses a complete message without applying the adaptive threshold.
§Errors
Returns Internal if a compressor fails.
Sourcepub fn decompress(
self,
input: &[u8],
max_size: usize,
) -> Result<Vec<u8>, Status>
pub fn decompress( self, input: &[u8], max_size: usize, ) -> Result<Vec<u8>, Status>
Decodes a message with a strict limit on the returned byte count.
Streaming decoders read at most one byte beyond the limit and never reserve output memory from an untrusted advertised decompressed size. Zstd’s decoding window is capped at 16 MiB independently of this limit; LZ4 frame blocks are bounded by the format’s 4 MiB maximum.
§Errors
Returns ResourceExhausted if output exceeds max_size, or
Internal if the compressed stream is malformed.
Trait Implementations§
Source§impl Clone for CompressionAlgorithm
impl Clone for CompressionAlgorithm
Source§fn clone(&self) -> CompressionAlgorithm
fn clone(&self) -> CompressionAlgorithm
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more