sq3_rs/file_header/
suggested_cache_size.rs

1use std::ops::Deref;
2
3use sq3_derive::Name;
4use sq3_parser::TypeName;
5
6use crate::{result::SqliteResult, traits::ParseBytes};
7
8/// # Suggested cache size (4 Bytes)
9///
10///  The 4-byte big-endian signed integer at offset 48 is the suggested cache
11/// size in pages for the database file. The value is a suggestion only and
12/// Sqlite is under no obligation to honor it. The absolute value of the integer
13/// is used as the suggested size. The suggested cache size can be set using the
14/// default_cache_size pragma.
15#[derive(Debug, Default, Name)]
16pub struct SuggestedCacheSize(u32);
17impl Deref for SuggestedCacheSize {
18    type Target = u32;
19
20    fn deref(&self) -> &Self::Target {
21        &self.0
22    }
23}
24
25impl ParseBytes for SuggestedCacheSize {
26    const LENGTH_BYTES: usize = 4;
27
28    fn parsing_handler(bytes: &[u8]) -> SqliteResult<Self> {
29        let buf: [u8; Self::LENGTH_BYTES] = bytes.try_into()?;
30
31        let database_size = u32::from_be_bytes(buf);
32
33        Ok(Self(database_size))
34    }
35}