1- package maxminddb
2-
3- import "github.com/oschwald/maxminddb-golang/v2/mmdbdata"
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.
1+ // Package mmdbdata provides low-level types and interfaces for custom MaxMind DB decoding.
82//
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.
3+ // This package allows custom decoding logic for applications that need fine-grained
4+ // control over how MaxMind DB data is processed. For most use cases, the high-level
5+ // maxminddb.Reader API is recommended instead.
6+ //
7+ // # Manual Decoding Example
128//
13- // Example :
9+ // Custom types can implement the Unmarshaler interface for custom decoding :
1410//
1511// type City struct {
1612// Names map[string]string `maxminddb:"names"`
1713// GeoNameID uint `maxminddb:"geoname_id"`
1814// }
1915//
20- // func (c *City) UnmarshalMaxMindDB(d *maxminddb .Decoder) error {
16+ // func (c *City) UnmarshalMaxMindDB(d *mmdbdata .Decoder) error {
2117// for key, err := range d.ReadMap() {
2218// if err != nil { return err }
2319// switch string(key) {
@@ -40,8 +36,18 @@ import "github.com/oschwald/maxminddb-golang/v2/mmdbdata"
4036// }
4137// return nil
4238// }
43- type Decoder = mmdbdata.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 = mmdbdata.Unmarshaler
39+ //
40+ // Types implementing Unmarshaler will automatically use custom decoding logic
41+ // instead of reflection when used with maxminddb.Reader.Lookup, similar to how
42+ // json.Unmarshaler works with encoding/json.
43+ //
44+ // # Direct Decoder Usage
45+ //
46+ // For even more control, you can use the Decoder directly:
47+ //
48+ // decoder := mmdbdata.NewDecoder(buffer, offset)
49+ // value, err := decoder.ReadString()
50+ // if err != nil {
51+ // return err
52+ // }
53+ package mmdbdata
0 commit comments