Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FrameInfo builder #99

Merged
merged 2 commits into from Apr 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 41 additions & 17 deletions src/frame/header.rs
Expand Up @@ -134,7 +134,7 @@
// |:----------:| ------ |:----------------:|
// | 4 bytes | | 0 - 4 bytes |
//
#[derive(Debug, Clone)]
#[derive(Debug, Default, Clone)]
/// The metadata for de/compressing with lz4 frame format.
pub struct FrameInfo {
/// If set, includes the total uncompressed size of data in the frame.
Expand All @@ -153,29 +153,53 @@
/// If set, includes a content checksum to verify that the full frame contents have been
/// decoded correctly.
pub content_checksum: bool,
/// If set, use legacy frame format
/// If set, use the legacy frame format
pub legacy_frame: bool,
}

impl Default for FrameInfo {
fn default() -> Self {
FrameInfo::new()
}
}

impl FrameInfo {
/// Create a new `FrameInfo`.
pub fn new() -> Self {
Self {
content_size: None,
dict_id: None,
block_size: BlockSize::default(),
block_mode: BlockMode::default(),
block_checksums: false,
content_checksum: false,
legacy_frame: false,
}
Self::default()
}

/// Whether to include the total uncompressed size of data in the frame.
pub fn content_size(mut self, content_size: Option<u64>) -> Self {
self.content_size = content_size;
self
}

Check warning on line 170 in src/frame/header.rs

View check run for this annotation

Codecov / codecov/patch

src/frame/header.rs#L167-L170

Added lines #L167 - L170 were not covered by tests

/// The maximum uncompressed size of each data block.
pub fn block_size(mut self, block_size: BlockSize) -> Self {
self.block_size = block_size;
self
}

Check warning on line 176 in src/frame/header.rs

View check run for this annotation

Codecov / codecov/patch

src/frame/header.rs#L173-L176

Added lines #L173 - L176 were not covered by tests

/// The block mode.
pub fn block_mode(mut self, block_mode: BlockMode) -> Self {
self.block_mode = block_mode;
self
}

Check warning on line 182 in src/frame/header.rs

View check run for this annotation

Codecov / codecov/patch

src/frame/header.rs#L179-L182

Added lines #L179 - L182 were not covered by tests

/// If set, includes a checksum for each data block in the frame.
pub fn block_checksums(mut self, block_checksums: bool) -> Self {
self.block_checksums = block_checksums;
self
}

Check warning on line 188 in src/frame/header.rs

View check run for this annotation

Codecov / codecov/patch

src/frame/header.rs#L185-L188

Added lines #L185 - L188 were not covered by tests

/// If set, includes a content checksum to verify that the full frame contents have been
/// decoded correctly.
pub fn content_checksum(mut self, content_checksum: bool) -> Self {
self.content_checksum = content_checksum;
self

Check warning on line 194 in src/frame/header.rs

View check run for this annotation

Codecov / codecov/patch

src/frame/header.rs#L192-L194

Added lines #L192 - L194 were not covered by tests
}

/// If set, use the legacy frame format.
pub fn legacy_frame(mut self, legacy_frame: bool) -> Self {
self.legacy_frame = legacy_frame;
self
}

Check warning on line 201 in src/frame/header.rs

View check run for this annotation

Codecov / codecov/patch

src/frame/header.rs#L198-L201

Added lines #L198 - L201 were not covered by tests

pub(crate) fn read_size(input: &[u8]) -> Result<usize, Error> {
let mut required = MIN_FRAME_INFO_SIZE;
let magic_num = u32::from_le_bytes(input[0..4].try_into().unwrap());
Expand Down