maxminddb/metadata.rs
1//! Database metadata types.
2
3use std::collections::BTreeMap;
4
5use serde::{Deserialize, Serialize};
6
7/// Metadata about the MaxMind DB file.
8#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
9pub struct Metadata {
10 /// Major version of the binary format (always 2).
11 pub binary_format_major_version: u16,
12 /// Minor version of the binary format (always 0).
13 pub binary_format_minor_version: u16,
14 /// Unix timestamp when the database was built.
15 pub build_epoch: u64,
16 /// Database type (e.g., "GeoIP2-City", "GeoLite2-Country").
17 pub database_type: String,
18 /// Map of language codes to database descriptions.
19 pub description: BTreeMap<String, String>,
20 /// IP version supported (4 or 6).
21 pub ip_version: u16,
22 /// Languages available in the database.
23 pub languages: Vec<String>,
24 /// Number of nodes in the search tree.
25 pub node_count: u32,
26 /// Size of each record in bits (24, 28, or 32).
27 pub record_size: u16,
28}
29
30impl Metadata {
31 /// Returns the database build time as a `SystemTime`.
32 ///
33 /// This converts the `build_epoch` Unix timestamp to a `SystemTime`.
34 ///
35 /// # Example
36 ///
37 /// ```
38 /// use maxminddb::Reader;
39 ///
40 /// let reader = Reader::open_readfile("test-data/test-data/GeoIP2-City-Test.mmdb").unwrap();
41 /// let build_time = reader.metadata.build_time();
42 /// println!("Database built: {:?}", build_time);
43 /// ```
44 #[must_use]
45 pub fn build_time(&self) -> std::time::SystemTime {
46 std::time::UNIX_EPOCH + std::time::Duration::from_secs(self.build_epoch)
47 }
48}