pub trait CompressedData<T, const MAX_UNCOMPRESSED_SIZE: u64, const COMPRESSION_LEVEL: i32>{
// Provided methods
fn from_boxed_slice(data: Box<[u8]>) -> Self { ... }
fn encode(uncompressed: &T) -> Result<(Self, usize)> { ... }
fn decode(&self) -> Result<(T, usize)> { ... }
fn decode_with_limit(&self, limit: ByteSize) -> Result<(T, usize)> { ... }
fn size_bytes(&self) -> usize { ... }
fn as_slice(&self) -> &[u8] ⓘ { ... }
}
Expand description
Helper trait for implementing a compressed structure for networking messages. The reason this is not a struct is because some derives do not work well on structs that have generics; e.g. ProtocolSchema.
Provided Methods§
Sourcefn from_boxed_slice(data: Box<[u8]>) -> Self
fn from_boxed_slice(data: Box<[u8]>) -> Self
Only use this if you are sure that the data is already encoded.
Sourcefn encode(uncompressed: &T) -> Result<(Self, usize)>
fn encode(uncompressed: &T) -> Result<(Self, usize)>
Borsh-serialize and compress the given data. Returns compressed data along with the raw (uncompressed) serialized data size.
Sourcefn decode(&self) -> Result<(T, usize)>
fn decode(&self) -> Result<(T, usize)>
Decompress and borsh-deserialize the compressed data. Returns decompressed and deserialized data along with the raw (uncompressed) serialized data size.
Sourcefn decode_with_limit(&self, limit: ByteSize) -> Result<(T, usize)>
fn decode_with_limit(&self, limit: ByteSize) -> Result<(T, usize)>
Decompress and borsh-deserialize the compressed data. Returns decompressed and deserialized data along with the raw (uncompressed) serialized data size.
fn size_bytes(&self) -> usize
fn as_slice(&self) -> &[u8] ⓘ
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.