1
+ package maxminddb
2
+
3
+ import "github.com/oschwald/maxminddb-golang/v2/internal/decoder"
4
+
5
+ // Decoder provides methods for decoding MaxMind DB data values.
6
+ // This interface is passed to UnmarshalMaxMindDB methods to allow
7
+ // custom decoding logic that avoids reflection for performance-critical applications.
8
+ //
9
+ // Types implementing Unmarshaler will automatically use custom decoding logic
10
+ // instead of reflection when used with Reader.Lookup, providing better performance
11
+ // for performance-critical applications.
12
+ //
13
+ // Example:
14
+ //
15
+ // type City struct {
16
+ // Names map[string]string `maxminddb:"names"`
17
+ // GeoNameID uint `maxminddb:"geoname_id"`
18
+ // }
19
+ //
20
+ // func (c *City) UnmarshalMaxMindDB(d *maxminddb.Decoder) error {
21
+ // for key, err := range d.DecodeMap() {
22
+ // if err != nil { return err }
23
+ // switch string(key) {
24
+ // case "names":
25
+ // names := make(map[string]string)
26
+ // for nameKey, nameErr := range d.DecodeMap() {
27
+ // if nameErr != nil { return nameErr }
28
+ // value, valueErr := d.DecodeString()
29
+ // if valueErr != nil { return valueErr }
30
+ // names[string(nameKey)] = value
31
+ // }
32
+ // c.Names = names
33
+ // case "geoname_id":
34
+ // geoID, err := d.DecodeUInt32()
35
+ // if err != nil { return err }
36
+ // c.GeoNameID = uint(geoID)
37
+ // default:
38
+ // if err := d.SkipValue(); err != nil { return err }
39
+ // }
40
+ // }
41
+ // return nil
42
+ // }
43
+ type Decoder = decoder.Decoder
44
+
45
+ // Unmarshaler is implemented by types that can unmarshal MaxMind DB data.
46
+ // This follows the same pattern as json.Unmarshaler and other Go standard library interfaces.
47
+ type Unmarshaler = decoder.Unmarshaler
0 commit comments