sq3_rs/file_header/
application_id.rs

1use std::ops::Deref;
2
3use sq3_derive::Name;
4use sq3_parser::TypeName;
5
6use crate::{result::SqliteResult, traits::ParseBytes};
7
8/// # Application ID (4 Bytes)
9///
10///  The 4-byte big-endian integer at offset 68 is an "Application ID" that can
11/// be set by the PRAGMA application_id command in order to identify the
12/// database as belonging to or associated with a particular application. The
13/// application ID is intended for database files used as an application
14/// file-format. The application ID can be used by utilities such as file(1) to
15/// determine the specific file type rather than just reporting
16/// "Sqlite3 Database". A list of assigned application IDs can be seen by
17/// consulting the magic.txt file in the Sqlite source repository.
18#[derive(Debug, Default, Name)]
19pub struct ApplicationId(u32);
20
21impl Deref for ApplicationId {
22    type Target = u32;
23
24    fn deref(&self) -> &Self::Target {
25        &self.0
26    }
27}
28
29impl ParseBytes for ApplicationId {
30    const LENGTH_BYTES: usize = 4;
31    fn parsing_handler(bytes: &[u8]) -> SqliteResult<Self> {
32        let buf: [u8; Self::LENGTH_BYTES] = bytes.try_into()?;
33
34        let value = u32::from_be_bytes(buf);
35
36        Ok(Self(value))
37    }
38}