Function fr32::write_unpadded[][src]

pub fn write_unpadded<W: ?Sized>(
    source: &[u8],
    target: &mut W,
    offset: usize,
    len: usize
) -> Result<usize> where
    W: Write
Expand description

Padding process.

Read a source of raw byte-aligned data, pad it in a bit stream and write a byte-aligned version of it in the target. The target needs to implement (besides Write) the Read and Seek traits since the last byte written may be incomplete and will need to be rewritten.

The reader will always be byte-aligned, the writer will operate with bit precision since we may have (when calling this function multiple times) a written target with extra bits (that need to be overwritten) and also incomplete data units. The ideal alignment scenario is for the writer to be positioned at the byte-aligned element boundary and just write whole chunks of data_chunk_bits (full data units) followed by its corresponding padding. To get there then we need to handle the potential bit-level misalignments:

  1. extra bits: the last byte is only partially valid so we need to get some bits from the source to overwrite them.
  2. Incomplete data unit: we need to fill the rest of it and add the padding to form a element that would position the writer at the desired boundary.