pub struct Header {
pub version: u16,
pub cache_type: u16,
pub generation_time: u32,
pub index_base_address: u32,
pub index_end_address: u32,
}Expand description
Parsed xdb file header (first 16 bytes of meaningful data in the 256-byte header block).
§Fields
version— xdb format version (typically 2)cache_type— cache strategy hintgeneration_time— Unix timestamp of database generationindex_base_address— file offset where segment index startsindex_end_address— file offset where segment index ends (inclusive)
§Example
let data = xdb_parse::load_file("./assets/ip2region_v4.xdb".into())?;
let header = xdb_parse::Header::parse(&data)?;
println!("xdb v{}, generated at {}", header.version, header.generation_time);Fields§
§version: u16§cache_type: u16§generation_time: u32§index_base_address: u32§index_end_address: u32Implementations§
Source§impl Header
impl Header
Sourcepub fn parse(data: &[u8]) -> Result<Self, XdbError>
pub fn parse(data: &[u8]) -> Result<Self, XdbError>
Parse the header from the first bytes of an xdb file.
Reads fields from the header block (offsets 0..16 within the 256-byte header).
Sourcepub fn ip_version(&self) -> Result<IpVersion, XdbError>
pub fn ip_version(&self) -> Result<IpVersion, XdbError>
Detect the IP version by examining the segment index size.
Uses the segment index range (index_end_address - index_base_address)
to determine whether segments are 14 bytes (IPv4) or 38 bytes (IPv6).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Header
impl RefUnwindSafe for Header
impl Send for Header
impl Sync for Header
impl Unpin for Header
impl UnsafeUnpin for Header
impl UnwindSafe for Header
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more