diff options
author | Oscar Najera <hi@oscarnajera.com> | 2025-06-06 20:16:29 +0200 |
---|---|---|
committer | Oscar Najera <hi@oscarnajera.com> | 2025-06-07 11:14:32 +0200 |
commit | 17f03d92e1e01c381e0f6f4421f653b67ab0819a (patch) | |
tree | f293450662a8765f349dd3bdeff15374c3e9e720 /geoip | |
parent | 034ffc3f4d4290a46d77cf463e9fed437f6d3e21 (diff) | |
download | scratch-17f03d92e1e01c381e0f6f4421f653b67ab0819a.tar.gz scratch-17f03d92e1e01c381e0f6f4421f653b67ab0819a.tar.bz2 scratch-17f03d92e1e01c381e0f6f4421f653b67ab0819a.zip |
Parse floats
Diffstat (limited to 'geoip')
-rw-r--r-- | geoip/geoip.asd | 1 | ||||
-rw-r--r-- | geoip/ip.lisp | 7 |
2 files changed, 7 insertions, 1 deletions
diff --git a/geoip/geoip.asd b/geoip/geoip.asd index 53826dd..a25cb8c 100644 --- a/geoip/geoip.asd +++ b/geoip/geoip.asd @@ -5,6 +5,7 @@ :license "GPL-3" :depends-on ("cffi" "mmap" + "ieee-floats" "split-sequence") :components ((:file "ip")) :description "Query maxminddb for ip information" diff --git a/geoip/ip.lisp b/geoip/ip.lisp index 7b6a23e..d97f5c2 100644 --- a/geoip/ip.lisp +++ b/geoip/ip.lisp @@ -172,13 +172,14 @@ (ecase type (1 (mread-pointer db-ptr length)) (2 (mread-uft8 db-ptr length)) - (3 (cons 'double (mread-unsigned db-ptr 8))) + (3 (ieee-floats:decode-float64 (mread-unsigned db-ptr 8))) (4 (bytes-from-foreign db-ptr length)) ((5 6 9 10) (mread-unsigned db-ptr length)) (7 (mread-map db-ptr length)) (8 (mread-int32 db-ptr length)) (11 (mread-list db-ptr length)) (14 (< 0 length)) ; bool + (15 (ieee-floats:decode-float32 (mread-unsigned db-ptr 4))) ))) (defun read-node-record (mmdb node-number bit) @@ -243,3 +244,7 @@ (with-slots (ptr fd size) mmdb (mmap:munmap ptr fd size))) +(defmacro with-mmdb ((mmdb file) &body body) + `(mmap:with-mmap (ptr fd size ,file) + (let ((,mmdb (mmap->mmdb ,file ptr fd size))) + ,@body))) |