Skip to main content

decode_block

Function decode_block 

Source
pub fn decode_block(
    which: Codec,
    codec: &dyn BlockCodec,
    input: &Bytes,
    uncompressed: u32,
    out: &mut DecodeBuf,
    cap: u64,
) -> Result<Option<Bytes>, Error>
Expand description

Decodes one block of a bundle with codec (the codec of which), as every caller does (package C’s bundle; implemented by the scaffold).

Starts the block’s segment in out, capped at cap bytes (DecodeBuf::begin_block with LimitKind::BlockOutput, and uncompressed as the size its room grows to while what it writes fits it), runs the codec, and checks what it returned: Ok(None) when the output is in the segment; Ok(Some(bytes)), the slice of input, when the codec named a range of its input, which must lie within the input, leave the segment empty, and fit cap as if it had been written. A range outside the input, or one returned with bytes written, is the codec’s error (Error::Decompress); a range longer than cap is LimitKind::BlockOutput. A codec that left its segment (began one of its own, which would lift its cap and its work count, or cut the buffer below its block, erasing earlier blocks of the run) is the codec’s error too, whatever it returned (round 6: Written was trusted).