pub struct BlockHeader {
pub compressed_size: u32,
pub original_size: u32,
}Expand description
Sizes of one framed block, shared by both framings.
Each block on the wire holds the compressed size, the original size, and the payload, in that order.
§Examples
use bzip3_rs::BlockHeader;
let header = BlockHeader::new(10, 100);
let bytes = header.to_bytes();
assert_eq!(bytes.len(), BlockHeader::LEN);
assert_eq!(BlockHeader::from_bytes(&bytes), header);Fields§
§compressed_size: u32Compressed payload bytes after this header.
original_size: u32Original bytes the payload decodes to.
Implementations§
Source§impl BlockHeader
impl BlockHeader
Sourcepub const fn new(compressed_size: u32, original_size: u32) -> Self
pub const fn new(compressed_size: u32, original_size: u32) -> Self
Build a block header from both sizes.
§Examples
use bzip3_rs::BlockHeader;
let header = BlockHeader::new(10, 100);
assert_eq!(header.compressed_size, 10);
assert_eq!(header.original_size, 100);Sourcepub fn for_block(payload_len: usize, original_len: usize) -> Result<Self>
pub fn for_block(payload_len: usize, original_len: usize) -> Result<Self>
Build the header for one encoded block.
§Errors
Returns Error::BlockTooLarge when a size does not fit 32 bits.
§Examples
use bzip3_rs::BlockHeader;
let header = BlockHeader::for_block(10, 100)?;
assert_eq!(header, BlockHeader::new(10, 100));Sourcepub const fn to_bytes(self) -> [u8; 8]
pub const fn to_bytes(self) -> [u8; 8]
Encode the header as 8 little-endian bytes.
§Examples
use bzip3_rs::BlockHeader;
let bytes = BlockHeader::new(1, 2).to_bytes();
assert_eq!(bytes, [1, 0, 0, 0, 2, 0, 0, 0]);Sourcepub const fn from_bytes(bytes: &[u8; 8]) -> Self
pub const fn from_bytes(bytes: &[u8; 8]) -> Self
Decode a header from 8 wire bytes.
§Examples
use bzip3_rs::BlockHeader;
let header = BlockHeader::from_bytes(&[1, 0, 0, 0, 2, 0, 0, 0]);
assert_eq!(header, BlockHeader::new(1, 2));Trait Implementations§
Source§impl Clone for BlockHeader
impl Clone for BlockHeader
impl Copy for BlockHeader
Source§impl Debug for BlockHeader
impl Debug for BlockHeader
impl Eq for BlockHeader
Source§impl Hash for BlockHeader
impl Hash for BlockHeader
Source§impl PartialEq for BlockHeader
impl PartialEq for BlockHeader
impl StructuralPartialEq for BlockHeader
Auto Trait Implementations§
impl Freeze for BlockHeader
impl RefUnwindSafe for BlockHeader
impl Send for BlockHeader
impl Sync for BlockHeader
impl Unpin for BlockHeader
impl UnsafeUnpin for BlockHeader
impl UnwindSafe for BlockHeader
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