Skip to main content

Reader

Struct Reader 

Source
pub struct Reader<'a> { /* private fields */ }
Expand description

High-level read-only reader for .coi columnar IP databases.

Thread-safe (Send + Sync): share across threads with Arc<Reader<'static>>.

Implementations§

Source§

impl Reader<'static>

Source

pub fn open(path: impl AsRef<Path>) -> Result<Self>

Open a .coi file from disk (uses memory mapping when mmap feature is enabled, else File).

Source

pub fn open_with_options( path: impl AsRef<Path>, options: ReaderOptions, ) -> Result<Self>

Open a .coi file with custom cache/verification options.

Source

pub fn open_file(path: impl AsRef<Path>) -> Result<Self>

Open a .coi file using explicit File positioned I/O (no mmap).

Source

pub fn open_file_with_options( path: impl AsRef<Path>, options: ReaderOptions, ) -> Result<Self>

Open a .coi file using File I/O with custom options.

Source

pub fn from_vec(bytes: Vec<u8>) -> Result<Self>

Open a .coi database from an owned byte buffer.

Source

pub fn from_vec_with_options( bytes: Vec<u8>, options: ReaderOptions, ) -> Result<Self>

Open from an owned Vec<u8> with custom options.

Source§

impl<'a> Reader<'a>

Source

pub fn from_bytes(bytes: &'a [u8]) -> Result<Self>

Open a .coi database directly from a borrowed byte slice (zero-copy).

Source

pub fn from_bytes_with_options( bytes: &'a [u8], options: ReaderOptions, ) -> Result<Self>

Open from a borrowed byte slice with custom options.

Source

pub fn header(&self) -> &FileHeader

Source

pub fn sections(&self) -> &[SectionEntry]

Source

pub fn metadata(&self) -> &Value

Source

pub fn schema(&self) -> &Schema

Source

pub fn zstd_dict_count(&self) -> usize

Source

pub fn ipv6_aliases(&self) -> &Ipv6Aliases

Source

pub fn ipv6_host_ext(&self) -> &Ipv6HostExt

Source

pub fn ipv4_entry_count(&self) -> u64

Source

pub fn ipv6_entry_count(&self) -> u64

Source

pub fn ipv4_transitions(&self) -> Result<Vec<(u32, u64)>>

Return all IPv4 merged transition points (start_u32, record_id) in ascending order.

Source

pub fn ipv6_transitions(&self) -> Result<Vec<(u64, u64)>>

Return all native IPv6 /64 merged transition points (start_hi64, record_id) in ascending order.

Source

pub fn ipv4_ranges(&self) -> Result<Vec<(u32, u32, u64)>>

Return all populated inclusive IPv4 ranges (start_u32, end_u32, record_id) (record_id > 0).

Source

pub fn ipv6_ranges(&self) -> Result<Vec<(u64, u64, u64)>>

Return all populated inclusive IPv6 /64 ranges (start_hi64, end_hi64, record_id) (record_id > 0).

Source

pub fn dict_entry_counts(&self) -> Vec<(String, u64)>

Source

pub fn verify_checksums(&self) -> Result<()>

Verify CRC32C checksums of every section in the .coi file.

Source

pub fn clear_caches(&self)

Clear all LRU caches (useful for benchmarking cold lookups).

Source

pub fn compile_projection<I, S>(&self, paths: I) -> Result<Projection>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Compile a column projection once at startup for fast projected lookups.

Source

pub fn lookup_record_id(&self, ip: IpAddr) -> Result<u64>

Resolve an IpAddr to its internal 1-based record_id (0 = NotFound).

Source

pub fn lookup_ipv4_record_id(&self, ip: Ipv4Addr) -> Result<u64>

Source

pub fn lookup_ipv6_record_id(&self, ip: Ipv6Addr) -> Result<u64>

Source

pub fn get_record_by_id( &self, record_id: u64, projection: Option<&Projection>, ) -> Result<Option<BTreeMap<String, Value>>>

Materialize a unique record directly by 1-based record_id (1..=record_count).

Source

pub fn lookup_value(&self, ip: IpAddr) -> Result<Option<Value>>

Look up an IP address and return its full dynamic record (BTreeMap<String, Value>).

Source

pub fn lookup_projected( &self, ip: IpAddr, projection: &Projection, ) -> Result<Option<Value>>

Look up an IP address and materialize ONLY the fields selected by projection.

Source

pub fn lookup<T: for<'de> Deserialize<'de>>( &self, ip: IpAddr, ) -> Result<Option<T>>

Look up an IP address and deserialize the full record directly into a typed serde struct T without constructing any intermediate BTreeMap or Value.

Source

pub fn lookup_with_projection<T: for<'de> Deserialize<'de>>( &self, ip: IpAddr, projection: &Projection, ) -> Result<Option<T>>

Look up an IP address using a compiled Projection and deserialize directly into T (zero intermediate BTreeMap / Value allocation).

Auto Trait Implementations§

§

impl<'a> !Freeze for Reader<'a>

§

impl<'a> Forget for Reader<'a>

§

impl<'a> Move for Reader<'a>

§

impl<'a> RefUnwindSafe for Reader<'a>

§

impl<'a> Send for Reader<'a>
where &'a [u8]: Send, RawVecInner: Send, MmapInner: Send, Mutex<File>: Send, NodeRef<Owned, String, Value, LeafOrInternal>: Send, BoxRaw<(String, Value)>: Send, BoxRaw<ColumnType>: Send, Mutex<LruCache<u32, Arc<DecodedBlockU32>>>: Send, Mutex<LruCache<u32, Arc<DecodedBlockU64>>>: Send, OnceLock<Arc<DecodedChunk>>: Send, BoxRaw<FlatDictReader>: Send, OnceLock<Arc<DecodedListDict>>: Send, Mutex<LruCache<(u32, u16, u32), Arc<DecodedChunk>>>: Send,

§

impl<'a> Sync for Reader<'a>
where RawVecInner: Sync, MmapInner: Sync, Mutex<File>: Sync, NodeRef<Owned, String, Value, LeafOrInternal>: Sync, BoxRaw<(String, Value)>: Sync, BoxRaw<ColumnType>: Sync, Mutex<LruCache<u32, Arc<DecodedBlockU32>>>: Sync, Mutex<LruCache<u32, Arc<DecodedBlockU64>>>: Sync, OnceLock<Arc<DecodedChunk>>: Sync, BoxRaw<FlatDictReader>: Sync, OnceLock<Arc<DecodedListDict>>: Sync, Mutex<LruCache<(u32, u16, u32), Arc<DecodedChunk>>>: Sync,

§

impl<'a> Unpin for Reader<'a>
where &'a [u8]: Unpin, *const u8 is !null: Unpin, *mut c_void: Unpin, Align4<u32>: Unpin, Align1<u8>: Unpin, I32NotAllOnes: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin, Box<ColumnType>: Unpin, *const u32: Unpin, *const LruEntry<u32, Arc<DecodedBlockU32>> is !null: Unpin, NonZero<usize>: Unpin, *mut LruEntry<u32, Arc<DecodedBlockU32>>: Unpin, *const LruEntry<u32, Arc<DecodedBlockU64>> is !null: Unpin, *mut LruEntry<u32, Arc<DecodedBlockU64>>: Unpin, Arc<DecodedChunk>: Unpin, Box<FlatDictReader>: Unpin, Arc<DecodedListDict>: Unpin, *const (u32, u16, u32): Unpin, *const LruEntry<(u32, u16, u32), Arc<DecodedChunk>> is !null: Unpin, *mut LruEntry<(u32, u16, u32), Arc<DecodedChunk>>: Unpin,

§

impl<'a> UnsafeUnpin for Reader<'a>

§

impl<'a> UnwindSafe for Reader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.