pub struct BuildOptions {
pub profile_codec: Codec,
pub zstd_level: i32,
pub train_zstd_dicts: bool,
pub index_block_size: u32,
pub ipv4_l1_bits: u8,
pub ipv6_l1_bits: u8,
pub row_group_size: u32,
pub struct_dict_row_group_size: u32,
pub dict_block_size: u32,
pub row_order: RowOrderStrategy,
pub prune: Option<PruneConfig>,
}Expand description
Build options for creating .coi files.
Fields§
§profile_codec: CodecCompression profile codec (Codec::Zstd for Compact, Codec::Lz4 for UltraFast, Codec::None for raw).
zstd_level: i32Zstd compression level (1..=19, default 9; ignored for non-Zstd profiles).
train_zstd_dicts: boolWhether to automatically train Section 3: ZstdDicts for IP index blocks (Compact profile).
index_block_size: u32Granule block size for IPv4/IPv6 transition indexes (default 2048 for Compact, 512 for UltraFast).
ipv4_l1_bits: u8L1 direct bucket prefix bits for IPv4 index (default 16).
ipv6_l1_bits: u8L1 direct bucket prefix bits for IPv6 index (default 0; sparse index is ~11 KB in L1 cache).
row_group_size: u32RowGroup size for RecordColumns (default 4096 for Compact, 1024 for UltraFast).
struct_dict_row_group_size: u32RowGroup size for StructDict tables (default 2048 for Compact, 512 for UltraFast).
dict_block_size: u32Block size for large FlatDict tables (> 8192 entries, default 4096).
row_order: RowOrderStrategyRow ordering strategy for unique records.
prune: Option<PruneConfig>Optional build-time field pruning (auto-deduplicates records & collapses IP transitions).
Implementations§
Source§impl BuildOptions
impl BuildOptions
Sourcepub fn compact() -> Self
pub fn compact() -> Self
Default Compact profile: Zstd blocks + trained Zstd dictionaries for maximum compression (~4.5–5.5×).
Examples found in repository?
25fn main() -> Result<(), Box<dyn std::error::Error>> {
26 let mut builder = CoipBuilder::new(BuildOptions::compact());
27 builder.set_metadata_field("database_type", serde_json::json!("Custom-Threat-IP"));
28 builder.add_ipv6_alias(AliasRule {
29 prefix: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0, 0, 0, 0],
30 prefix_len: 96,
31 v4_bit_offset: 96,
32 });
33
34 // Broad corporate /16 overridden by a specific /24 and an explicit deleted /32 hole
35 builder.insert_ipv4_cidr(
36 Ipv4Addr::new(10, 20, 0, 0),
37 16,
38 make_record("Corp-Default", "US", "United States", 10),
39 )?;
40 builder.insert_ipv4_cidr(
41 Ipv4Addr::new(10, 20, 30, 0),
42 24,
43 make_record("Corp-DMZ", "DE", "Germany", 85),
44 )?;
45 builder.delete_ipv4_cidr(Ipv4Addr::new(10, 20, 30, 1), 32)?;
46
47 // Native IPv6 /48 + exact /128 host override
48 builder.insert_ipv6_cidr(
49 "2001:db8:abcd::".parse::<Ipv6Addr>()?,
50 48,
51 make_record("IPv6-Pool", "JP", "Japan", 20),
52 )?;
53 builder.insert_ipv6_cidr(
54 "2001:db8:abcd::99".parse::<Ipv6Addr>()?,
55 128,
56 make_record("IPv6-Honeypot", "JP", "Japan", 99),
57 )?;
58
59 let (full_bytes, full_stats) = builder.build()?;
60 println!(
61 "Built full .coi: {} bytes ({} unique records, {} IPv4 transitions, {} IPv6 transitions)",
62 full_bytes.len(),
63 full_stats.record_count,
64 full_stats.v4_transitions,
65 full_stats.v6_transitions
66 );
67
68 // Same dataset with build-time field pruning (keep only country.iso_code, country.name, org)
69 let mut pruned_opts = BuildOptions::ultrafast();
70 pruned_opts.prune = Some(PruneConfig {
71 keep_fields: Some(vec![
72 "org".into(),
73 "country.iso_code".into(),
74 "country.name".into(),
75 ]),
76 });
77 let mut builder2 = CoipBuilder::new(pruned_opts);
78 builder2.insert_ipv4_cidr(
79 Ipv4Addr::new(10, 20, 0, 0),
80 16,
81 make_record("Corp-Default", "US", "United States", 10),
82 )?;
83 let (pruned_bytes, pruned_stats) = builder2.build()?;
84 println!(
85 "Built pruned UltraFast .coi: {} bytes ({} unique records)",
86 pruned_bytes.len(),
87 pruned_stats.record_count
88 );
89
90 Ok(())
91}Sourcepub fn ultrafast() -> Self
pub fn ultrafast() -> Self
UltraFast profile: pure-Rust LZ4 blocks + fine-grained 512/1024 chunks for microsecond cold lookups.
Examples found in repository?
25fn main() -> Result<(), Box<dyn std::error::Error>> {
26 let mut builder = CoipBuilder::new(BuildOptions::compact());
27 builder.set_metadata_field("database_type", serde_json::json!("Custom-Threat-IP"));
28 builder.add_ipv6_alias(AliasRule {
29 prefix: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0, 0, 0, 0],
30 prefix_len: 96,
31 v4_bit_offset: 96,
32 });
33
34 // Broad corporate /16 overridden by a specific /24 and an explicit deleted /32 hole
35 builder.insert_ipv4_cidr(
36 Ipv4Addr::new(10, 20, 0, 0),
37 16,
38 make_record("Corp-Default", "US", "United States", 10),
39 )?;
40 builder.insert_ipv4_cidr(
41 Ipv4Addr::new(10, 20, 30, 0),
42 24,
43 make_record("Corp-DMZ", "DE", "Germany", 85),
44 )?;
45 builder.delete_ipv4_cidr(Ipv4Addr::new(10, 20, 30, 1), 32)?;
46
47 // Native IPv6 /48 + exact /128 host override
48 builder.insert_ipv6_cidr(
49 "2001:db8:abcd::".parse::<Ipv6Addr>()?,
50 48,
51 make_record("IPv6-Pool", "JP", "Japan", 20),
52 )?;
53 builder.insert_ipv6_cidr(
54 "2001:db8:abcd::99".parse::<Ipv6Addr>()?,
55 128,
56 make_record("IPv6-Honeypot", "JP", "Japan", 99),
57 )?;
58
59 let (full_bytes, full_stats) = builder.build()?;
60 println!(
61 "Built full .coi: {} bytes ({} unique records, {} IPv4 transitions, {} IPv6 transitions)",
62 full_bytes.len(),
63 full_stats.record_count,
64 full_stats.v4_transitions,
65 full_stats.v6_transitions
66 );
67
68 // Same dataset with build-time field pruning (keep only country.iso_code, country.name, org)
69 let mut pruned_opts = BuildOptions::ultrafast();
70 pruned_opts.prune = Some(PruneConfig {
71 keep_fields: Some(vec![
72 "org".into(),
73 "country.iso_code".into(),
74 "country.name".into(),
75 ]),
76 });
77 let mut builder2 = CoipBuilder::new(pruned_opts);
78 builder2.insert_ipv4_cidr(
79 Ipv4Addr::new(10, 20, 0, 0),
80 16,
81 make_record("Corp-Default", "US", "United States", 10),
82 )?;
83 let (pruned_bytes, pruned_stats) = builder2.build()?;
84 println!(
85 "Built pruned UltraFast .coi: {} bytes ({} unique records)",
86 pruned_bytes.len(),
87 pruned_stats.record_count
88 );
89
90 Ok(())
91}Trait Implementations§
Source§impl Clone for BuildOptions
impl Clone for BuildOptions
Source§impl Debug for BuildOptions
impl Debug for BuildOptions
Auto Trait Implementations§
impl Forget for BuildOptions
impl Freeze for BuildOptions
impl Move for BuildOptions
impl RefUnwindSafe for BuildOptions
impl Send for BuildOptionswhere
RawVecInner: Send,
impl Sync for BuildOptionswhere
RawVecInner: Sync,
impl Unpin for BuildOptions
impl UnsafeUnpin for BuildOptions
impl UnwindSafe for BuildOptionswhere
RawVecInner: UnwindSafe,
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more