Skip to content

z-------------/nim-mmdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API: mmdb

import mmdb

type MMDBDataKind

MMDBDataKind = enum
 mdkNone, mdkPointer = 1, mdkString = 2, mdkDouble = 3, mdkBytes = 4, mdkU16 = 5, mdkU32 = 6, mdkMap = 7, mdkI32 = 8, mdkU64 = 9, mdkU128 = 10, mdkArray = 11, mdkInvalid12, mdkInvalid13, mdkBoolean = 14, mdkFloat = 15

type MMDBData

MMDBData = object
 case kind*: MMDBDataKind
 of mdkString:
 stringVal*: string

 of mdkDouble:
 doubleVal*: float64

 of mdkBytes:
 bytesVal*: string

 of mdkU16, mdkU32, mdkU64:
 u64Val*: uint64

 of mdkU128:
 u128Val*: string

 of mdkI32:
 i32Val*: int32

 of mdkMap:
 mapVal*: OrderedTable[MMDBData, MMDBData]

 of mdkArray:
 arrayVal*: seq[MMDBData]

 of mdkBoolean:
 booleanVal*: bool

 of mdkFloat:
 floatVal*: float32

 of mdkPointer, mdkNone, mdkInvalid12, mdkInvalid13:
 nil

type MMDB

MMDB = object
 metadata*: Option[MMDBData]
 s*: Stream
 size: int
 recordSizeBits: uint64
 nodeSizeBits: uint64
 nodeCount: uint64
 treeSize: uint64
 dataSectionStart: uint64

proc hash

proc hash(x: MMDBData): Hash

proc ==

proc `==`(a, b: MMDBData): bool

proc ==

proc `==`(a: MMDBData; b: uint64): bool

proc >

proc `>`(a: MMDBData; b: uint64): bool

proc ==

proc `==`(a: MMDBData; b: string): bool

proc toMMDB

proc toMMDB(stringVal: string): MMDBData

proc toMMDB

proc toMMDB(mapVal: OrderedTable[MMDBData, MMDBData]): MMDBData

proc toMMDB

proc toMMDB(mapVal: openArray[(MMDBData, MMDBData)]): MMDBData

template m

template m(s: string): MMDBData

proc []

proc `[]`(x: MMDBData; key: MMDBData): MMDBData {.raises: [ValueError, KeyError].}

proc []

proc `[]`(x: MMDBData; key: string): MMDBData {.raises: [ValueError, KeyError], tags: [].}

proc $

proc `$`(x: MMDBData): string

proc readControlByte

proc readControlByte(s: Stream): (MMDBDataKind, int) {.raises: [IOError, OSError], tags: [ReadIOEffect].}

proc readPointer

proc readPointer(s: Stream; value: int): uint64 {.raises: [IOError, OSError, ValueError], tags: [ReadIOEffect].}

proc readNode

proc readNode(s: Stream; bit: uint8; recordSizeBits: uint64): uint64 {.raises: [IOError, OSError, ValueError], tags: [ReadIOEffect].}

proc decode

proc decode(mmdb: MMDB): MMDBData {.raises: [IOError, OSError, ValueError, Exception], tags: [ReadIOEffect, RootEffect].}

proc lookup

proc lookup(mmdb: MMDB; ipAddr: openArray[uint8]): MMDBData {.raises: [ValueError, IOError, OSError, KeyError, Exception], tags: [ReadIOEffect, RootEffect].}

proc lookup

proc lookup(mmdb: MMDB; ipAddrStr: string): MMDBData {.raises: [ValueError, KeyError, IOError, OSError, Exception], tags: [ReadIOEffect, RootEffect].}

proc openFile

proc openFile(mmdb: var MMDB; stream: Stream) {.raises: [IOError, OSError, ValueError, Exception, KeyError], tags: [ReadIOEffect, RootEffect].}

proc openFile

proc openFile(mmdb: var MMDB; file: File) {.raises: [IOError, OSError, ValueError, Exception, KeyError], tags: [ReadIOEffect, RootEffect].}

proc openFile

proc openFile(mmdb: var MMDB; filename: string) {.raises: [IOError, OSError, ValueError, Exception, KeyError], tags: [ReadIOEffect, RootEffect].}

proc initMMDB

proc initMMDB(filename: string): MMDB {.raises: [IOError, OSError, ValueError, Exception, KeyError], tags: [ReadIOEffect, RootEffect].}

proc initMMDB

proc initMMDB(file: File): MMDB {.raises: [IOError, OSError, ValueError, Exception, KeyError], tags: [ReadIOEffect, RootEffect].}

proc close

proc close(mmdb: MMDB) {.raises: [Exception, IOError, OSError], tags: [WriteIOEffect].}

About

MaxMind DB file reader in pure Nim.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages