geocoder_core/index/
format.rs1use serde::{Deserialize, Serialize};
16
17pub const MAGIC: &[u8; 8] = b"GEOCODER";
18pub const VERSION: u32 = 2;
19pub const HEADER_SIZE: usize = 16;
20pub const SECTION_HEADER_SIZE: usize = 17;
21
22#[repr(u8)]
23#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
24pub enum SectionKind {
25 Meta = 0,
27 TokenFst = 1,
29 PostingOffsets = 2,
31 PostingsByDoc = 3,
33 PostingsByScore = 4,
35 PairOffsets = 5,
37 PairBlobs = 6,
39 NgramFst = 7,
41 NgramOffsets = 8,
42 NgramBlobs = 9,
43 GeohashFst = 10,
45 GeohashOffsets = 11,
46 GeohashBlobs = 12,
47 FilterFst = 13,
49 FilterOffsets = 14,
50 FilterBlobs = 15,
51 DocOffsets = 16,
53 DocBlobs = 17,
55 Postal = 18,
59}
60
61impl SectionKind {
62 pub const OPTIONAL: [SectionKind; 1] = [Self::Postal];
64
65 pub const ALL: [SectionKind; 19] = [
66 Self::Meta,
67 Self::TokenFst,
68 Self::PostingOffsets,
69 Self::PostingsByDoc,
70 Self::PostingsByScore,
71 Self::PairOffsets,
72 Self::PairBlobs,
73 Self::NgramFst,
74 Self::NgramOffsets,
75 Self::NgramBlobs,
76 Self::GeohashFst,
77 Self::GeohashOffsets,
78 Self::GeohashBlobs,
79 Self::FilterFst,
80 Self::FilterOffsets,
81 Self::FilterBlobs,
82 Self::DocOffsets,
83 Self::DocBlobs,
84 Self::Postal,
85 ];
86}
87
88impl TryFrom<u8> for SectionKind {
89 type Error = u8;
90 fn try_from(v: u8) -> Result<Self, u8> {
91 Self::ALL.iter().copied().find(|k| *k as u8 == v).ok_or(v)
92 }
93}
94
95#[derive(Debug, Clone, Copy)]
96pub struct SectionHeader {
97 pub kind: SectionKind,
98 pub offset: u64,
99 pub length: u64,
100}
101
102#[derive(Debug, Clone, Serialize, Deserialize)]
104pub struct Meta {
105 pub profile: String,
106 pub profile_version: u32,
107 pub documents: u32,
108 pub tokens: u32,
109}