Skip to content

feat(mmdb): stdlib-only MaxMind DB reader - #2

Merged
zxdev merged 1 commit into
mainfrom
feat/mmdb-reader
Jul 24, 2026
Merged

feat(mmdb): stdlib-only MaxMind DB reader#2
zxdev merged 1 commit into
mainfrom
feat/mmdb-reader

Conversation

@zxdev

@zxdev zxdev commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Adds a from-scratch, standard-library-only MaxMind DB (.mmdb) reader to the root cidr package — the read companion to the mmdb-write command.

mmdb-write uses the third-party maxmind/mmdbwriter and is isolated in its own module for that reason. The reader is implemented on the stdlib and lives in the root package, so downstream consumers (e.g. the planned aegis intel plane) can read cidr-produced databases through a first-party API with zero third-party transitive dependencies — the root module's go.mod stays empty.

API

OpenMMDB(path) / OpenMMDBBytes(b) / (*MMDB).Lookup(net.IP) (map[string]any, bool, error) / Metadata() / Close().

Coverage (MaxMind DB v2 format)

  • Metadata parse; 24/28/32-bit search-tree record encodings; IPv4-in-IPv6 (::/96) lookups.
  • Full data decoder: string, uint16/32/64, int32, double, float, bytes, bool, map, array, uint128, and data-section pointers (deduplicated records).
  • Tests over mmdb-write-produced fixtures: ASN across all three record sizes, nested-map Country records, deduped records resolved through pointers, IPv4/IPv6/not-found, and open-error paths.

Fixtures are small and committed because the stdlib-only root can't synthesize MMDBs in-test the way the writer module does; .gitignore keeps large corpora ignored while tracking test-*.mmdb.

go test -race ./... green; staticcheck clean; root go.mod unchanged (still dependency-free).

The read companion to the mmdb-write command. mmdb-write depends on the
third-party maxmind/mmdbwriter and is isolated in its own module for that
reason; the reader is implemented from scratch on the standard library and lives
in the root package, so downstream consumers can read cidr-produced databases
(ASN, country, or any custom schema) through a first-party API with ZERO
third-party transitive dependencies — the root module's go.mod stays empty.

- OpenMMDB / OpenMMDBBytes / Lookup / Metadata / Close.
- Full MaxMind DB v2 format: metadata parse, 24/28/32-bit search-tree records,
  IPv4-in-IPv6 (::/96) lookups, and the complete data decoder (string, uint16/32/64,
  int32, double, float, bytes, bool, map, array, uint128, and data-section pointers).
- Tests over mmdb-write-produced fixtures: ASN across all three record sizes,
  nested-map Country records, deduped records resolved via data-section pointers,
  IPv4/IPv6/not-found, and open-error paths. Fixtures are small and committed
  (the stdlib-only root can't synthesize MMDBs in-test the way the writer module
  does); .gitignore keeps large corpora ignored while tracking test-*.mmdb.
@zxdev
zxdev merged commit c0e3651 into main Jul 24, 2026
1 check passed
@zxdev
zxdev deleted the feat/mmdb-reader branch July 24, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant