pub fn decode_using_format_from(
    bytes: &[u8],
    format: Format
) -> Result<Decoder<'_>, CodecError>
Expand description

SCALE decode a bit sequence using the given format, handing back an iterator of booleans.

Example

use scale_bits::scale::{
    encode_using_format,
    decode_using_format_from,
    format::{ Format, StoreFormat, OrderFormat },
};

let bits = vec![true, true, false, true];

// Encode the bits to have something to decode:
let encoded = encode_using_format(
    bits.iter().copied(),
    Format::new(StoreFormat::U8, OrderFormat::Msb0)
);

// Decode them again.
let decoder = decode_using_format_from(
    &encoded,
    Format::new(StoreFormat::U8, OrderFormat::Msb0)
).unwrap();
let new_bits: Result<Vec<bool>,_> = decoder.collect();

assert_eq!(bits, new_bits.unwrap());