Native MoonBit MaxMind DB reader with bounded decoding and exact values
git clone https://github.com/HhWw96/moonmmdb.git
cd moonmmdbnpm run build
npm run demonode bin/moonmmdb.mjs metadata tests/fixtures/GeoLite2-ASN-Test.mmdb
node bin/moonmmdb.mjs lookup tests/fixtures/GeoLite2-ASN-Test.mmdb 1.0.0.1 1.128.0.1
node bin/moonmmdb.mjs lookup tests/fixtures/GeoIP2-City-Test.mmdb 2001:218::
node bin/moonmmdb.mjs project tests/fixtures/GeoIP2-City-Test.mmdb 2001:218:: /country/iso_code /location/latitude
node bin/moonmmdb.mjs enrich tests/fixtures/GeoLite2-ASN-Test.mmdb examples/access.jsonl
node bin/moonmmdb.mjs enrich tests/fixtures/GeoLite2-ASN-Test.mmdb examples/access.jsonl --field /autonomous_system_number
node bin/moonmmdb.mjs enrich tests/fixtures/MaxMind-DB-test-ipv4-24.mmdb examples/nested-access.jsonl --ip-path /client/ip --field /ip
node bin/moonmmdb.mjs diff tests/fixtures/MaxMind-DB-test-ipv4-24.mmdb tests/fixtures/MaxMind-DB-test-ipv4-32.mmdb examples/database-check.jsonl
node bin/moonmmdb.mjs enrich-many examples/many.json examples/analysis-access.jsonl
node examples/log_analytics/run.mjs tests/scenarios/geo.mmdb tests/scenarios/asn.mmdb examples/analysis-access.jsonl| 退出码 | 含义 |
|---|---|
| 0 | 打开成功,或全部查询命中 |
| 1 | 至少一条未命中,无运行或输入错误 |
| 2 | 至少一条输入、文件读取或查询错误;优先于 1 |
moon add HhWw96/moonmmdb@0.4.0// moon.pkg: import { "HhWw96/moonmmdb" @mmdb }
let reader = @mmdb.open_bytes(database_bytes)
let result = reader.lookup("1.0.0.1")
match result.value {
Some(record) => println(record.to_tagged_json().stringify())
None => println("not found")
}
let selected = reader.project("1.0.0.1", ["/autonomous_system_number"])
println(selected.to_json().stringify())
let fields = @mmdb.prepare_fields(["/autonomous_system_number"])
let repeated = reader.project_prepared("1.0.0.1", fields)
println(repeated.to_json().stringify())node scripts/consumer-verify.mjsnpm run verify
python -m pip install --target .reference-deps -r requirements-reference.txt
python scripts/reference-verify.py
node scripts/benchmark.mjs
python scripts/scale-verify.py
node scripts/release-verify.mjspython scripts/setup-native-windows.py
python scripts/download-production.py
node scripts/extended-verify.mjspub struct Enricher {
// private fields
}pub struct FieldSelector {
// private fields
}pub struct Reader {
// private fields
}fn Reader::compare_prepared(self : Reader, other : Reader, ip : String, selector : FieldSelector) -> RecordDiff raise MmdbErrorfn Reader::project_prepared(self : Reader, ip : String, selector : FieldSelector) -> Projection raise MmdbErrorpub(all) struct RecordDiff {
before : Projection
after : Projection
record_changed : Bool
prefix_changed : Bool
changed_fields : Array[String]
} derive(Eq, Debug)pub(all) enum Value {
Text(String)
Blob(Bytes)
Boolean(Bool)
Unsigned16(UInt)
Unsigned32(UInt)
Signed32(Int)
Unsigned64(UInt64)
Unsigned128(String)
Real32(Float32Value)
Real64(Float64Value)
List(Array[Value])
Object(Array[(String, Value)])
} derive(Eq, Debug)Install
Download zipNative MoonBit MaxMind DB reader with bounded decoding and exact values