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}
56
57impl SectionKind {
58 pub const ALL: [SectionKind; 18] = [
59 Self::Meta,
60 Self::TokenFst,
61 Self::PostingOffsets,
62 Self::PostingsByDoc,
63 Self::PostingsByScore,
64 Self::PairOffsets,
65 Self::PairBlobs,
66 Self::NgramFst,
67 Self::NgramOffsets,
68 Self::NgramBlobs,
69 Self::GeohashFst,
70 Self::GeohashOffsets,
71 Self::GeohashBlobs,
72 Self::FilterFst,
73 Self::FilterOffsets,
74 Self::FilterBlobs,
75 Self::DocOffsets,
76 Self::DocBlobs,
77 ];
78}
79
80impl TryFrom<u8> for SectionKind {
81 type Error = u8;
82 fn try_from(v: u8) -> Result<Self, u8> {
83 Self::ALL.iter().copied().find(|k| *k as u8 == v).ok_or(v)
84 }
85}
86
87#[derive(Debug, Clone, Copy)]
88pub struct SectionHeader {
89 pub kind: SectionKind,
90 pub offset: u64,
91 pub length: u64,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize)]
96pub struct Meta {
97 pub profile: String,
98 pub profile_version: u32,
99 pub documents: u32,
100 pub tokens: u32,
101}