Enum BlockSize

Source
pub enum BlockSize<B> {
Show 15 variants Samples192, Samples576, Samples1152, Samples2304, Samples4608, Uncommon8(B), Uncommon16(B), Samples256, Samples512, Samples1024, Samples2048, Samples4096, Samples8192, Samples16384, Samples32768,
}
Expand description

Possible block sizes in a FLAC frame, in samples

Common sizes are stored as a 4-bit value, while uncommon sizes are stored as 8 or 16 bit values.

BitsBlock Size
0000invalid
0001192
0010576
00111152
01002304
01014606
01108 bit field (+1)
011116 bit field (+1)
1000256
1001512
10101024
10112048
11004096
11018192
111016384
111132768

Handing uncommon block sizes is why this type is a generic with two different implementations from reading from a bitstream. The first reads common sizes, while the second reads additional bits if necessary.

§Example

use flac_codec::stream::BlockSize;
use bitstream_io::{BitReader, BitRead, BigEndian};

let data: &[u8] = &[
    0b0110_1001,              // block size + sample rate
    0b0000_100_0,             // channels + bps + pad
    0x00,                     // frame number
    0x13,                     // uncommon block size (+1)
];

let mut r = BitReader::endian(data, BigEndian);
let block_size = r.parse::<BlockSize<()>>().unwrap();  // reads 0b0110
assert_eq!(
    block_size,
    BlockSize::Uncommon8(()),  // need to read actual block size from end of frame
);
r.skip(4 + 8 + 8).unwrap();    // skip unnecessary bits for this example
assert_eq!(
    // read remainder of block size from end of frame
    r.parse_using::<BlockSize<u16>>(block_size).unwrap(),
    BlockSize::Uncommon8(0x13 + 1),
);

Variants§

§

Samples192

192 samples

§

Samples576

576 samples

§

Samples1152

1152 samples

§

Samples2304

2304 samples

§

Samples4608

4608 samples

§

Uncommon8(B)

Uncommon 8 bit sample count + 1

§

Uncommon16(B)

Uncommon 16 bit sample count + 1

§

Samples256

256 samples

§

Samples512

512 samples

§

Samples1024

1024 samples

§

Samples2048

2048 samples

§

Samples4096

4096 samples

§

Samples8192

8192 samples

§

Samples16384

16384 samples

§

Samples32768

32768 samples

Trait Implementations§

Source§

impl<B: Clone> Clone for BlockSize<B>

Source§

fn clone(&self) -> BlockSize<B>

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<B: Debug> Debug for BlockSize<B>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for BlockSize<u16>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<BlockSize<u16>> for u16

Source§

fn from(size: BlockSize<u16>) -> Self

Converts to this type from the input type.
Source§

impl FromBitStream for BlockSize<()>

Source§

type Error = Error

Error generated during parsing, such as io::Error
Source§

fn from_reader<R: BitRead + ?Sized>(r: &mut R) -> Result<Self, Self::Error>

Parse Self from reader
Source§

impl FromBitStreamUsing for BlockSize<u16>

Source§

type Context = BlockSize<()>

Some context to consume when parsing
Source§

type Error = Error

Error generated during parsing, such as io::Error
Source§

fn from_reader<R: BitRead + ?Sized>( r: &mut R, size: BlockSize<()>, ) -> Result<Self, Error>

Parse Self from reader with the given context
Source§

impl<B: PartialEq> PartialEq for BlockSize<B>

Source§

fn eq(&self, other: &BlockSize<B>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

const fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<B> ToBitStream for BlockSize<B>

Source§

type Error = Error

Error generated during building, such as io::Error
Source§

fn to_writer<W: BitWrite + ?Sized>(&self, w: &mut W) -> Result<(), Self::Error>

Generate self to writer
Source§

fn bits<C>(&self) -> Result<C, Self::Error>
where C: Counter, Self: Sized,

Returns length of self in bits, if possible
Source§

fn bits_len<C, E>(&self) -> Result<C, Self::Error>
where C: Counter, E: Endianness, Self: Sized,

👎Deprecated since 4.0.0: use of bits() is preferred
Returns total length of self, if possible
Source§

impl TryFrom<u16> for BlockSize<u16>

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(size: u16) -> Result<Self, Error>

Performs the conversion.
Source§

impl<B: Copy> Copy for BlockSize<B>

Source§

impl<B: Eq> Eq for BlockSize<B>

Source§

impl<B> StructuralPartialEq for BlockSize<B>

Auto Trait Implementations§

§

impl<B> Freeze for BlockSize<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for BlockSize<B>
where B: RefUnwindSafe,

§

impl<B> Send for BlockSize<B>
where B: Send,

§

impl<B> Sync for BlockSize<B>
where B: Sync,

§

impl<B> Unpin for BlockSize<B>
where B: Unpin,

§

impl<B> UnwindSafe for BlockSize<B>
where B: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.