Skip to main content

Crate coip_reader

Crate coip_reader 

Source
Expand description

High-performance, thread-safe read-only reader for COI (.coi) v1.0 columnar IP databases.

§Features

  • mmap (default): zero-copy memory-mapped file opening via Reader::open
  • serde (default): direct zero-intermediate-allocation streaming deserialization via Reader::lookup and Reader::lookup_with_projection
  • zstd-c (optional): switch from pure-Rust ruzstd to C libzstd for maximum cold throughput

§Example

use std::collections::BTreeMap;
use std::net::{IpAddr, Ipv4Addr};
use coip_builder::{BuildOptions, CoipBuilder};
use coip_reader::{Reader, Value};

let mut builder = CoipBuilder::new(BuildOptions::compact());
let mut rec = BTreeMap::new();
rec.insert("iso_code".into(), Value::Utf8("US".into()));
rec.insert("asn".into(), Value::U32(15169));
builder.insert_ipv4_cidr(Ipv4Addr::new(8, 8, 8, 0), 24, rec).unwrap();
let (bytes, _) = builder.build().unwrap();

let reader = Reader::from_bytes(&bytes).unwrap();
let proj = reader.compile_projection(["iso_code"]).unwrap();
let hit = reader
    .lookup_projected(IpAddr::V4(Ipv4Addr::new(8, 8, 8, 8)), &proj)
    .unwrap()
    .unwrap();
assert_eq!(hit.as_map().unwrap().get("iso_code"), Some(&Value::Utf8("US".into())));
assert!(!hit.as_map().unwrap().contains_key("asn"));

Re-exports§

pub use error::ReaderError;
pub use error::Result;
pub use projection::Projection;
pub use reader::Reader;
pub use reader::ReaderOptions;

Modules§

cache
Lock-sharded concurrent LRU cache for high-throughput multi-threaded reads.
codec
Block/section decompression with pure-Rust ruzstd + lz4_flex default, optional zstd-c feature, and Section 3: ZstdDicts support.
error
index_reader
IPv4 (Section 5) and IPv6 (Section 6) index readers with L1 direct buckets, Section 3: ZstdDicts, all 5 RidModes, and 16-shard concurrent LRU block cache.
projection
Compiled Column Projection for skipping unrequested columns and dictionaries.
reader
High-level .coi database reader (Reader).
serde_de
Direct streaming serde::Deserializer over columnar RowGroups & Dictionaries (zero intermediate BTreeMap / Value allocation) plus from_value helper.
source
Backing storage abstractions (&[u8], Vec<u8>, mmap, File).
table_reader
ColumnTable & DictTables readers with rank-indexed validity bitmaps and LRU chunk caches.

Structs§

FileHeader
Fixed 64-byte COI file header at offset 0.
Schema
Complete self-describing Schema stored in Section 2.
SectionEntry
32-byte entry in the Section Directory.

Enums§

SectionKind
Section kind identifier in the Section Directory.
Value
Lossless, self-describing dynamic value supporting all COI / MMDB types.