cassandra_proto/compression.rs
1//!CDRS support traffic decompression as it is described in [Apache
2//!Cassandra protocol](
3//!https://github.com/apache/cassandra/blob/trunk/doc/native_protocol_v4.spec#L790)
4//!
5//!Before being used, client and server must agree on a compression algorithm to
6//!use, which is done in the STARTUP message. As a consequence, a STARTUP message
7//!must never be compressed. However, once the STARTUP frame has been received
8//!by the server, messages can be compressed (including the response to the STARTUP
9//!request).
10
11use std::error::Error;
12
13/// Compressor trait that defines functionality
14/// which should be provided by typical compressor.
15pub trait Compressor {
16 type CompressorError: Sized + Error;
17 /// Encodes given bytes and returns `Result` that contains either
18 /// encoded data or an error which occures during the transformation.
19 fn encode(&self, bytes: Vec<u8>) -> Result<Vec<u8>, Self::CompressorError>;
20 /// Encodes given encoded data and returns `Result` that contains either
21 /// encoded bytes or an error which occures during the transformation.
22 fn decode(&self, bytes: Vec<u8>) -> Result<Vec<u8>, Self::CompressorError>;
23 /// Returns a string which is a name of a compressor. This name should be
24 /// exactly the same as one which server returns in a response to
25 /// `Options` request.
26 fn into_string(&self) -> Option<String>;
27}