pub struct StreamHeader {
pub block_size: BlockSize,
}Expand description
Streaming frame header: the magic bytes and the block size.
The header is 9 bytes long. It records the requested block size verbatim. No clamp applies: short inputs still encode under the configured size. Blocks follow it until the input ends.
§Examples
use bzip3_rs::{BlockSize, MAGIC_NUMBER, StreamHeader};
let header = StreamHeader::new(BlockSize::MIN);
let bytes = header.to_bytes();
assert_eq!(bytes.len(), StreamHeader::LEN);
assert!(bytes.starts_with(&MAGIC_NUMBER));
assert_eq!(StreamHeader::from_bytes(&bytes)?, header);Fields§
§block_size: BlockSizeLargest original block size in the stream.
Implementations§
Source§impl StreamHeader
impl StreamHeader
Sourcepub const fn new(block_size: BlockSize) -> Self
pub const fn new(block_size: BlockSize) -> Self
Build a header for block_size.
§Examples
use bzip3_rs::{BlockSize, StreamHeader};
let header = StreamHeader::new(BlockSize::DEFAULT);
assert_eq!(header.block_size, BlockSize::DEFAULT);Sourcepub const fn to_bytes(self) -> [u8; 9]
pub const fn to_bytes(self) -> [u8; 9]
Encode the header into its 9 bytes.
The first 5 bytes are the magic number. The last 4 bytes are the block size as a little-endian integer.
§Examples
use bzip3_rs::{BlockSize, StreamHeader};
let bytes = StreamHeader::new(BlockSize::MIN).to_bytes();
assert_eq!(&bytes[..5], b"BZ3v1");
assert_eq!(bytes[5..], BlockSize::MIN.get().to_le_bytes());Sourcepub fn from_bytes(bytes: &[u8; 9]) -> Result<Self>
pub fn from_bytes(bytes: &[u8; 9]) -> Result<Self>
Parse the 9 header bytes.
§Errors
Returns Error::InvalidMagic on bad magic,
Error::InvalidBlockSize on a block size outside the valid range.
§Examples
use bzip3_rs::error::Error;
use bzip3_rs::{BlockSize, StreamHeader};
let bytes = StreamHeader::new(BlockSize::MIN).to_bytes();
assert_eq!(StreamHeader::from_bytes(&bytes)?.block_size, BlockSize::MIN);
let bad = [0_u8; StreamHeader::LEN];
assert!(matches!(StreamHeader::from_bytes(&bad), Err(Error::InvalidMagic)));Trait Implementations§
Source§impl Clone for StreamHeader
impl Clone for StreamHeader
impl Copy for StreamHeader
Source§impl Debug for StreamHeader
impl Debug for StreamHeader
impl Eq for StreamHeader
Source§impl Hash for StreamHeader
impl Hash for StreamHeader
Source§impl PartialEq for StreamHeader
impl PartialEq for StreamHeader
impl StructuralPartialEq for StreamHeader
Auto Trait Implementations§
impl Freeze for StreamHeader
impl RefUnwindSafe for StreamHeader
impl Send for StreamHeader
impl Sync for StreamHeader
impl Unpin for StreamHeader
impl UnsafeUnpin for StreamHeader
impl UnwindSafe for StreamHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more