@@ -11,19 +11,19 @@ import (
11
11
"github.com/oschwald/maxminddb-golang/v2/internal/mmdberrors"
12
12
)
13
13
14
- // Decoder is a decoder for the MMDB data section.
15
- type Decoder struct {
14
+ // ReflectionDecoder is a decoder for the MMDB data section.
15
+ type ReflectionDecoder struct {
16
16
DataDecoder
17
17
}
18
18
19
- // New creates a [Decoder ].
20
- func New (buffer []byte ) Decoder {
21
- return Decoder {DataDecoder : NewDataDecoder (buffer )}
19
+ // New creates a [ReflectionDecoder ].
20
+ func New (buffer []byte ) ReflectionDecoder {
21
+ return ReflectionDecoder {DataDecoder : NewDataDecoder (buffer )}
22
22
}
23
23
24
24
// Decode decodes the data value at offset and stores it in the value
25
25
// pointed at by v.
26
- func (d * Decoder ) Decode (offset uint , v any ) error {
26
+ func (d * ReflectionDecoder ) Decode (offset uint , v any ) error {
27
27
rv := reflect .ValueOf (v )
28
28
if rv .Kind () != reflect .Ptr || rv .IsNil () {
29
29
return errors .New ("result param must be a pointer" )
@@ -38,7 +38,7 @@ func (d *Decoder) Decode(offset uint, v any) error {
38
38
return err
39
39
}
40
40
41
- func (d * Decoder ) decode (offset uint , result reflect.Value , depth int ) (uint , error ) {
41
+ func (d * ReflectionDecoder ) decode (offset uint , result reflect.Value , depth int ) (uint , error ) {
42
42
if depth > maximumDataStructureDepth {
43
43
return 0 , mmdberrors .NewInvalidDatabaseError (
44
44
"exceeded maximum data structure depth; database is likely corrupt" ,
@@ -58,7 +58,7 @@ func (d *Decoder) decode(offset uint, result reflect.Value, depth int) (uint, er
58
58
59
59
// DecodePath decodes the data value at offset and stores the value assocated
60
60
// with the path in the value pointed at by v.
61
- func (d * Decoder ) DecodePath (
61
+ func (d * ReflectionDecoder ) DecodePath (
62
62
offset uint ,
63
63
path []any ,
64
64
v any ,
@@ -147,7 +147,7 @@ PATH:
147
147
return err
148
148
}
149
149
150
- func (d * Decoder ) decodeFromType (
150
+ func (d * ReflectionDecoder ) decodeFromType (
151
151
dtype Type ,
152
152
size uint ,
153
153
offset uint ,
@@ -242,7 +242,7 @@ func indirect(result reflect.Value) reflect.Value {
242
242
243
243
var sliceType = reflect .TypeOf ([]byte {})
244
244
245
- func (d * Decoder ) unmarshalBytes (size , offset uint , result reflect.Value ) (uint , error ) {
245
+ func (d * ReflectionDecoder ) unmarshalBytes (size , offset uint , result reflect.Value ) (uint , error ) {
246
246
value , newOffset , err := d .decodeBytes (size , offset )
247
247
if err != nil {
248
248
return 0 , err
@@ -263,7 +263,9 @@ func (d *Decoder) unmarshalBytes(size, offset uint, result reflect.Value) (uint,
263
263
return newOffset , mmdberrors .NewUnmarshalTypeError (value , result .Type ())
264
264
}
265
265
266
- func (d * Decoder ) unmarshalFloat32 (size , offset uint , result reflect.Value ) (uint , error ) {
266
+ func (d * ReflectionDecoder ) unmarshalFloat32 (
267
+ size , offset uint , result reflect.Value ,
268
+ ) (uint , error ) {
267
269
if size != 4 {
268
270
return 0 , mmdberrors .NewInvalidDatabaseError (
269
271
"the MaxMind DB file's data section contains bad data (float32 size of %v)" ,
@@ -288,7 +290,9 @@ func (d *Decoder) unmarshalFloat32(size, offset uint, result reflect.Value) (uin
288
290
return newOffset , mmdberrors .NewUnmarshalTypeError (value , result .Type ())
289
291
}
290
292
291
- func (d * Decoder ) unmarshalFloat64 (size , offset uint , result reflect.Value ) (uint , error ) {
293
+ func (d * ReflectionDecoder ) unmarshalFloat64 (
294
+ size , offset uint , result reflect.Value ,
295
+ ) (uint , error ) {
292
296
if size != 8 {
293
297
return 0 , mmdberrors .NewInvalidDatabaseError (
294
298
"the MaxMind DB file's data section contains bad data (float 64 size of %v)" ,
@@ -316,15 +320,15 @@ func (d *Decoder) unmarshalFloat64(size, offset uint, result reflect.Value) (uin
316
320
return newOffset , mmdberrors .NewUnmarshalTypeError (value , result .Type ())
317
321
}
318
322
319
- func (d * Decoder ) unmarshalInt32 (size , offset uint , result reflect.Value ) (uint , error ) {
323
+ func (d * ReflectionDecoder ) unmarshalInt32 (size , offset uint , result reflect.Value ) (uint , error ) {
320
324
if size > 4 {
321
325
return 0 , mmdberrors .NewInvalidDatabaseError (
322
326
"the MaxMind DB file's data section contains bad data (int32 size of %v)" ,
323
327
size ,
324
328
)
325
329
}
326
330
327
- value , newOffset , err := d .decodeInt (size , offset )
331
+ value , newOffset , err := d .decodeInt32 (size , offset )
328
332
if err != nil {
329
333
return 0 , err
330
334
}
@@ -356,7 +360,7 @@ func (d *Decoder) unmarshalInt32(size, offset uint, result reflect.Value) (uint,
356
360
return newOffset , mmdberrors .NewUnmarshalTypeError (value , result .Type ())
357
361
}
358
362
359
- func (d * Decoder ) unmarshalMap (
363
+ func (d * ReflectionDecoder ) unmarshalMap (
360
364
size uint ,
361
365
offset uint ,
362
366
result reflect.Value ,
@@ -381,7 +385,7 @@ func (d *Decoder) unmarshalMap(
381
385
}
382
386
}
383
387
384
- func (d * Decoder ) unmarshalPointer (
388
+ func (d * ReflectionDecoder ) unmarshalPointer (
385
389
size , offset uint ,
386
390
result reflect.Value ,
387
391
depth int ,
@@ -394,7 +398,7 @@ func (d *Decoder) unmarshalPointer(
394
398
return newOffset , err
395
399
}
396
400
397
- func (d * Decoder ) unmarshalSlice (
401
+ func (d * ReflectionDecoder ) unmarshalSlice (
398
402
size uint ,
399
403
offset uint ,
400
404
result reflect.Value ,
@@ -415,7 +419,7 @@ func (d *Decoder) unmarshalSlice(
415
419
return 0 , mmdberrors .NewUnmarshalTypeStrError ("array" , result .Type ())
416
420
}
417
421
418
- func (d * Decoder ) unmarshalString (size , offset uint , result reflect.Value ) (uint , error ) {
422
+ func (d * ReflectionDecoder ) unmarshalString (size , offset uint , result reflect.Value ) (uint , error ) {
419
423
value , newOffset , err := d .decodeString (size , offset )
420
424
if err != nil {
421
425
return 0 , err
@@ -434,7 +438,7 @@ func (d *Decoder) unmarshalString(size, offset uint, result reflect.Value) (uint
434
438
return newOffset , mmdberrors .NewUnmarshalTypeError (value , result .Type ())
435
439
}
436
440
437
- func (d * Decoder ) unmarshalUint (
441
+ func (d * ReflectionDecoder ) unmarshalUint (
438
442
size , offset uint ,
439
443
result reflect.Value ,
440
444
uintType uint ,
@@ -447,7 +451,7 @@ func (d *Decoder) unmarshalUint(
447
451
)
448
452
}
449
453
450
- value , newOffset , err := d .decodeUint (size , offset )
454
+ value , newOffset , err := d .decodeUint64 (size , offset )
451
455
if err != nil {
452
456
return 0 , err
453
457
}
@@ -480,7 +484,9 @@ func (d *Decoder) unmarshalUint(
480
484
481
485
var bigIntType = reflect .TypeOf (big.Int {})
482
486
483
- func (d * Decoder ) unmarshalUint128 (size , offset uint , result reflect.Value ) (uint , error ) {
487
+ func (d * ReflectionDecoder ) unmarshalUint128 (
488
+ size , offset uint , result reflect.Value ,
489
+ ) (uint , error ) {
484
490
if size > 16 {
485
491
return 0 , mmdberrors .NewInvalidDatabaseError (
486
492
"the MaxMind DB file's data section contains bad data (uint128 size of %v)" ,
@@ -508,7 +514,7 @@ func (d *Decoder) unmarshalUint128(size, offset uint, result reflect.Value) (uin
508
514
return newOffset , mmdberrors .NewUnmarshalTypeError (value , result .Type ())
509
515
}
510
516
511
- func (d * Decoder ) decodeMap (
517
+ func (d * ReflectionDecoder ) decodeMap (
512
518
size uint ,
513
519
offset uint ,
514
520
result reflect.Value ,
@@ -547,7 +553,7 @@ func (d *Decoder) decodeMap(
547
553
return offset , nil
548
554
}
549
555
550
- func (d * Decoder ) decodeSlice (
556
+ func (d * ReflectionDecoder ) decodeSlice (
551
557
size uint ,
552
558
offset uint ,
553
559
result reflect.Value ,
@@ -564,7 +570,7 @@ func (d *Decoder) decodeSlice(
564
570
return offset , nil
565
571
}
566
572
567
- func (d * Decoder ) decodeStruct (
573
+ func (d * ReflectionDecoder ) decodeStruct (
568
574
size uint ,
569
575
offset uint ,
570
576
result reflect.Value ,
0 commit comments