Skip to main content

BlockCodec

Trait BlockCodec 

Source
pub trait BlockCodec: Send + Sync {
    // Required method
    fn decode(
        &self,
        input: &Bytes,
        uncompressed: u32,
        out: &mut DecodeBuf,
    ) -> Result<Decoded, Error>;

    // Provided methods
    fn compressor(
        &self,
        _which: Codec,
        _meter: &Arc<Meter>,
    ) -> Result<Option<Arc<dyn BlockCodec>>, SaveError> { ... }
    fn decode_with_flags(
        &self,
        input: &Bytes,
        uncompressed: u32,
        _flags: u32,
        out: &mut DecodeBuf,
    ) -> Result<Decoded, Error> { ... }
    fn compress(
        &self,
        data: &[u8],
        which: Codec,
        meter: &Arc<Meter>,
    ) -> Result<Bytes, SaveError> { ... }
    fn chunk_size(
        &self,
        which: Codec,
        _meter: &Arc<Meter>,
    ) -> Result<usize, SaveError> { ... }
}
Expand description

Decodes one block.

Required Methods§

Source

fn decode( &self, input: &Bytes, uncompressed: u32, out: &mut DecodeBuf, ) -> Result<Decoded, Error>

Decodes input, a block’s stored bytes (a slice of the bundle). uncompressed is blocks-info’s declared size; each codec treats it as UnityPy does (module docs). The output goes into out, which pays and checks the caps before it grows, and the codec returns Decoded::Written; or, with out left empty, the codec returns Decoded::Input, a range of input (the stored codec), which decode_block checks and slices.

ⓘ
// A codec cannot return bytes of its own (round 5: a buffer it
// allocated was kept in the bundle's runs, charged to nothing).
use unityrs_core::budget::DecodeBuf;
use unityrs_core::codec::BlockCodec;
use unityrs_core::{Bytes, Error};
struct Own;
impl BlockCodec for Own {
    fn decode(&self, _: &Bytes, _: u32, _: &mut DecodeBuf) -> Result<Option<Bytes>, Error> {
        Ok(Some(Bytes::from(vec![0u8; 1 << 20])))
    }
}

Provided Methods§

Source

fn compressor( &self, _which: Codec, _meter: &Arc<Meter>, ) -> Result<Option<Arc<dyn BlockCodec>>, SaveError>

Capture a compressor and chunk policy for one payload, when needed. The default uses this registered codec directly.

Source

fn decode_with_flags( &self, input: &Bytes, uncompressed: u32, _flags: u32, out: &mut DecodeBuf, ) -> Result<Decoded, Error>

Decode with the original bundle flags available to extension callbacks. Native codecs use only their registered compression type.

Source

fn compress( &self, data: &[u8], which: Codec, meter: &Arc<Meter>, ) -> Result<Bytes, SaveError>

Compress a bundle block. The default preserves the native packer.

Source

fn chunk_size( &self, which: Codec, _meter: &Arc<Meter>, ) -> Result<usize, SaveError>

The writer’s chunk bound, looked up once before writing the payload.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§