CompressedData

Trait CompressedData 

Source
pub trait CompressedData<T, const MAX_UNCOMPRESSED_SIZE: u64, const COMPRESSION_LEVEL: i32>
where T: BorshSerialize + BorshDeserialize, Self: From<Box<[u8]>> + AsRef<Box<[u8]>>,
{ // 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§

Source

fn from_boxed_slice(data: Box<[u8]>) -> Self

Only use this if you are sure that the data is already encoded.

Source

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.

Source

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.

Source

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.

Source

fn size_bytes(&self) -> usize

Source

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.

Implementors§

Source§

impl CompressedData<EpochSyncProof, MAX_UNCOMPRESSED_EPOCH_SYNC_PROOF_SIZE, EPOCH_SYNC_COMPRESSION_LEVEL> for CompressedEpochSyncProof

Source§

impl CompressedData<ChunkStateWitness, MAX_UNCOMPRESSED_STATE_WITNESS_SIZE, STATE_WITNESS_COMPRESSION_LEVEL> for EncodedChunkStateWitness

Source§

impl CompressedData<ChunkStateWitnessV1, MAX_UNCOMPRESSED_STATE_WITNESS_SIZE, STATE_WITNESS_COMPRESSION_LEVEL> for EncodedChunkStateWitness