Skip to main content

CompressionRegistry

Struct CompressionRegistry 

Source
pub struct CompressionRegistry { /* private fields */ }
Expand description

Registry of compression providers.

The registry maps encoding names to their provider implementations. Use CompressionRegistry::default() to get a registry with all feature-enabled built-in providers.

Implementations§

Source§

impl CompressionRegistry

Source

pub fn new() -> Self

Create an empty compression registry.

Use register to add providers, or use default to get a registry with built-in providers.

Source

pub fn register<P: CompressionProvider>(self, provider: P) -> Self

Register a compression provider.

Returns self for method chaining.

§Example
use connectrpc::compression::{CompressionRegistry, GzipProvider, ZstdProvider};
let registry = CompressionRegistry::new()
    .register(GzipProvider::default())
    .register(ZstdProvider::default());
assert!(registry.supports("gzip"));
assert!(registry.supports("zstd"));
Source

pub fn get(&self, name: &str) -> Option<Arc<dyn CompressionProvider>>

Get a provider by encoding name.

Returns None if no provider is registered for the given name.

Source

pub fn supports(&self, name: &str) -> bool

Check if a provider is registered for the given encoding name.

Source

pub fn supported_encodings(&self) -> Vec<&'static str>

List all supported encoding names.

Source

pub fn accept_encoding_header(&self) -> &str

Get a comma-separated string of supported encodings.

Useful for Accept-Encoding headers. The string is computed once when providers are registered and cached, so this is a cheap lookup.

Source

pub fn negotiate_encoding( &self, accept_encoding: Option<&str>, request_encoding: Option<&str>, ) -> Option<&'static str>

Negotiate a response encoding based on the client’s accept-encoding header.

Returns the first encoding from the client’s preference list that this registry supports, or None if only identity is acceptable.

Per the Connect spec, the accept-encoding header is treated as an ordered list with most preferred first (no quality values).

If the client omits accept-encoding, the spec says the server may assume the client accepts the same encoding used for the request (if any), plus identity.

Source

pub fn decompress_with_limit( &self, encoding: &str, data: Bytes, max_size: usize, ) -> Result<Bytes, ConnectError>

Decompress data using the specified encoding with a size limit.

Returns an error if the encoding is not supported or if the decompressed data exceeds max_size. This protects against compression bomb attacks.

For identity encoding, returns the data without copying.

Source

pub fn compress( &self, encoding: &str, data: &[u8], ) -> Result<Bytes, ConnectError>

Compress data using the specified encoding.

Returns an error if the encoding is not supported.

Source

pub fn register_streaming<P: StreamingCompressionProvider>( self, provider: P, ) -> Self

Available on crate feature streaming only.

Register a streaming compression provider.

This also registers the provider for buffered compression. Returns self for method chaining.

Available when the streaming feature is enabled.

Source

pub fn get_streaming( &self, name: &str, ) -> Option<Arc<dyn StreamingCompressionProvider>>

Available on crate feature streaming only.

Get a streaming provider by encoding name.

Returns None if no streaming provider is registered for the given name.

Source

pub fn supports_streaming(&self, name: &str) -> bool

Available on crate feature streaming only.

Check if streaming compression is supported for the given encoding name.

Source

pub fn decompress_stream( &self, encoding: &str, reader: BoxedAsyncBufRead, ) -> Result<BoxedAsyncRead, ConnectError>

Available on crate feature streaming only.

Create a streaming decompressor for the specified encoding.

Returns an AsyncRead that decompresses data from the input reader. Returns an error if the encoding is not supported for streaming.

Source

pub fn compress_stream( &self, encoding: &str, reader: BoxedAsyncBufRead, ) -> Result<BoxedAsyncRead, ConnectError>

Available on crate feature streaming only.

Create a streaming compressor for the specified encoding.

Returns an AsyncRead that compresses data from the input reader. Returns an error if the encoding is not supported for streaming.

Trait Implementations§

Source§

impl Clone for CompressionRegistry

Source§

fn clone(&self) -> CompressionRegistry

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CompressionRegistry

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CompressionRegistry

Source§

fn default() -> Self

Create a registry with all feature-enabled built-in providers.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more