Skip to content

Commit

Permalink
fix number of chunks constant
Browse files Browse the repository at this point in the history
  • Loading branch information
lulf committed Apr 30, 2024
1 parent 0ad345e commit 0400177
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ pub use crate::page::ReadError;
use crate::page::{ChunkHeader, DehydratedPageReader, Header, PageHeader, PageReader, PageWriter};
use crate::types::{OptionPageID, PageID};


pub(crate) const CHUNKS_PER_PAGE: usize = (PAGE_SIZE - PageHeader::SIZE - size_of::<DataHeader>()).div_ceil(MAX_CHUNK_SIZE + ChunkHeader::SIZE);
pub const PAGE_MAX_PAYLOAD_SIZE: usize =
PAGE_SIZE - PageHeader::SIZE - size_of::<DataHeader>() - (page::CHUNKS_PER_PAGE * ChunkHeader::SIZE);
PAGE_SIZE - PageHeader::SIZE - (CHUNKS_PER_PAGE * ChunkHeader::SIZE) - size_of::<DataHeader>();


pub type FileID = u8;

Expand Down
3 changes: 1 addition & 2 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub(crate) const MAX_CHUNK_SIZE: usize = if config::MAX_CHUNK_SIZE > (PAGE_SIZE
} else {
config::MAX_CHUNK_SIZE
};
pub(crate) const CHUNKS_PER_PAGE: usize = (PAGE_SIZE - PageHeader::SIZE) / (MAX_CHUNK_SIZE + ChunkHeader::SIZE);

async fn write_header<F: Flash, H: Header>(flash: &mut F, page_id: PageID, header: H) -> Result<(), F::Error> {
assert!(size_of::<H>() <= MAX_HEADER_SIZE);
Expand Down Expand Up @@ -649,7 +648,7 @@ mod tests {

const HEADER: TestHeader = TestHeader { foo: 123456 };
const MAX_PAYLOAD: usize =
PAGE_SIZE - PageHeader::SIZE - size_of::<TestHeader>() - (ChunkHeader::SIZE * CHUNKS_PER_PAGE);
PAGE_SIZE - PageHeader::SIZE - size_of::<TestHeader>() - ChunkHeader::SIZE;

#[test_log::test]
fn test_crc32() {
Expand Down

0 comments on commit 0400177

Please sign in to comment.