use serde::{Deserialize, Serialize};
pub const MAGIC: &[u8; 8] = b"GEOCODER";
pub const VERSION: u32 = 2;
pub const HEADER_SIZE: usize = 16;
pub const SECTION_HEADER_SIZE: usize = 17;
#[repr(u8)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum SectionKind {
Meta = 0,
TokenFst = 1,
PostingOffsets = 2,
PostingsByDoc = 3,
PostingsByScore = 4,
PairOffsets = 5,
PairBlobs = 6,
NgramFst = 7,
NgramOffsets = 8,
NgramBlobs = 9,
GeohashFst = 10,
GeohashOffsets = 11,
GeohashBlobs = 12,
FilterFst = 13,
FilterOffsets = 14,
FilterBlobs = 15,
DocOffsets = 16,
DocBlobs = 17,
}
impl SectionKind {
pub const ALL: [SectionKind; 18] = [
Self::Meta,
Self::TokenFst,
Self::PostingOffsets,
Self::PostingsByDoc,
Self::PostingsByScore,
Self::PairOffsets,
Self::PairBlobs,
Self::NgramFst,
Self::NgramOffsets,
Self::NgramBlobs,
Self::GeohashFst,
Self::GeohashOffsets,
Self::GeohashBlobs,
Self::FilterFst,
Self::FilterOffsets,
Self::FilterBlobs,
Self::DocOffsets,
Self::DocBlobs,
];
}
impl TryFrom<u8> for SectionKind {
type Error = u8;
fn try_from(v: u8) -> Result<Self, u8> {
Self::ALL.iter().copied().find(|k| *k as u8 == v).ok_or(v)
}
}
#[derive(Debug, Clone, Copy)]
pub struct SectionHeader {
pub kind: SectionKind,
pub offset: u64,
pub length: u64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Meta {
pub profile: String,
pub profile_version: u32,
pub documents: u32,
pub tokens: u32,
}