sqlite_rs/header/
application_id.rs

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