1#![no_std]
35
36extern crate alloc;
37#[cfg(feature = "std")]
38extern crate std;
39
40pub mod column;
41pub mod crc32c;
42pub mod error;
43pub mod header;
44pub mod index;
45pub mod schema;
46pub mod value;
47pub mod varint;
48
49pub use column::{
50 COLUMN_TABLE_HEADER_SIZE, ChunkHeader, ColumnTableHeader, EncMode, FLAT_DICT_HEADER_SIZE,
51 FlatDictHeader, LIST_DICT_HEADER_SIZE, ListDictHeader, NullMode,
52};
53pub use crc32c::{crc32c, crc32c_append};
54pub use error::FormatError;
55pub use header::{
56 Codec, FOOTER_SIZE, FORMAT_MAJOR, FORMAT_MINOR, FileFooter, FileHeader, HEADER_SIZE,
57 MAGIC_FOOTER, MAGIC_HEADER, SECTION_ALIGN, SECTION_ENTRY_SIZE, SectionEntry, SectionKind,
58 align8, header_flags,
59};
60pub use index::{
61 ALIAS_RULE_SIZE, AliasRule, HOST_EXT_ENTRY_SIZE, HostExtEntry, INDEX_HEADER_SIZE, IndexHeader,
62 Ipv6Aliases, Ipv6HostExt, NO_ZSTD_DICT, RidMode, ZstdDicts, range_to_cidrs_v4,
63 range_to_cidrs_v6,
64};
65pub use schema::{
66 ColumnType, DictGroup, DictKind, DictSchema, IdWidth, PType, PhysicalColKind, SCHEMA_VERSION,
67 Schema, ShreddedMapEntry, StructField, StructSchema, TableSchema,
68};
69pub use value::Value;
70pub use varint::{
71 Cursor, read_svarint, read_uvarint, write_string, write_svarint, write_uvarint, zigzag_decode,
72 zigzag_encode,
73};
74
75#[cfg(test)]
76mod tests {
77 use super::*;
78 use alloc::string::String;
79 use alloc::vec;
80
81 #[test]
82 fn test_header_footer_schema_roundtrip() {
83 let hdr = FileHeader {
84 format_major: FORMAT_MAJOR,
85 format_minor: FORMAT_MINOR,
86 flags: header_flags::HAS_IPV4 | header_flags::HAS_IPV6,
87 profile_codec: Codec::Zstd,
88 section_count: 5,
89 header_ext_len: 0,
90 build_epoch: 1_700_000_000,
91 record_count: 672_963,
92 section_dir_offset: HEADER_SIZE as u64,
93 file_size: 20_000_000,
94 header_crc32c: 0,
95 };
96 let raw = hdr.encode();
97 let decoded = FileHeader::decode(&raw).unwrap();
98 assert_eq!(decoded.record_count, 672_963);
99 assert!(decoded.has_ipv4());
100 assert!(decoded.has_ipv6());
101 assert!(!decoded.has_ipv6_host_ext());
102
103 let footer = FileFooter {
104 dir_crc32c: 0x1234_5678,
105 section_dir_offset: 64,
106 };
107 let fraw = footer.encode();
108 assert_eq!(FileFooter::decode(&fraw).unwrap(), footer);
109
110 let schema = Schema {
111 dicts: vec![
112 DictSchema {
113 name: String::from("coords"),
114 kind: DictKind::Struct {
115 table: TableSchema {
116 column_count: 2,
117 root: StructSchema {
118 nullable: false,
119 presence_col: None,
120 fields: vec![
121 StructField {
122 name: String::from("latitude"),
123 col_type: ColumnType::Primitive {
124 ptype: PType::F64,
125 nullable: true,
126 col_id: 0,
127 },
128 },
129 StructField {
130 name: String::from("longitude"),
131 col_type: ColumnType::Primitive {
132 ptype: PType::F64,
133 nullable: true,
134 col_id: 1,
135 },
136 },
137 ],
138 dict_groups: vec![],
139 },
140 },
141 },
142 },
143 DictSchema {
144 name: String::from("tz"),
145 kind: DictKind::Flat {
146 ptype: PType::Utf8,
147 sorted_front_coded: false,
148 block_size: 0,
149 },
150 },
151 ],
152 root: TableSchema {
153 column_count: 2,
154 root: StructSchema {
155 nullable: false,
156 presence_col: None,
157 fields: vec![StructField {
158 name: String::from("location"),
159 col_type: ColumnType::Struct(StructSchema {
160 nullable: true,
161 presence_col: None,
162 fields: vec![StructField {
163 name: String::from("time_zone"),
164 col_type: ColumnType::DictRef {
165 dict_id: 1,
166 id_width: IdWidth::U16,
167 nullable: true,
168 col_id: 0,
169 },
170 }],
171 dict_groups: vec![DictGroup {
172 dict_id: 0,
173 id_width: IdWidth::U32,
174 col_id: 1,
175 field_names: vec![
176 String::from("latitude"),
177 String::from("longitude"),
178 ],
179 }],
180 }),
181 }],
182 dict_groups: vec![],
183 },
184 },
185 };
186 let sbytes = schema.encode();
187 let sdec = Schema::decode(&sbytes).unwrap();
188 assert_eq!(sdec, schema);
189 }
190}