@@ -27,8 +27,10 @@ const (
27
27
_Uint64
28
28
_Uint128
29
29
_Slice
30
- _Container
31
- _Marker
30
+ // We don't use the next two. They are placeholders. See the spec
31
+ // for more details.
32
+ _Container // nolint: deadcode, varcheck
33
+ _Marker // nolint: deadcode, varcheck
32
34
_Bool
33
35
_Float32
34
36
)
@@ -159,10 +161,8 @@ func (d *decoder) unmarshalBool(size uint, offset uint, result reflect.Value) (u
159
161
if size > 1 {
160
162
return 0 , newInvalidDatabaseError ("the MaxMind DB file's data section contains bad data (bool size of %v)" , size )
161
163
}
162
- value , newOffset , err := d .decodeBool (size , offset )
163
- if err != nil {
164
- return 0 , err
165
- }
164
+ value , newOffset := d .decodeBool (size , offset )
165
+
166
166
switch result .Kind () {
167
167
case reflect .Bool :
168
168
result .SetBool (value )
@@ -207,10 +207,8 @@ func (d *decoder) indirect(result reflect.Value) reflect.Value {
207
207
var sliceType = reflect .TypeOf ([]byte {})
208
208
209
209
func (d * decoder ) unmarshalBytes (size uint , offset uint , result reflect.Value ) (uint , error ) {
210
- value , newOffset , err := d .decodeBytes (size , offset )
211
- if err != nil {
212
- return 0 , err
213
- }
210
+ value , newOffset := d .decodeBytes (size , offset )
211
+
214
212
switch result .Kind () {
215
213
case reflect .Slice :
216
214
if result .Type () == sliceType {
@@ -230,10 +228,7 @@ func (d *decoder) unmarshalFloat32(size uint, offset uint, result reflect.Value)
230
228
if size != 4 {
231
229
return 0 , newInvalidDatabaseError ("the MaxMind DB file's data section contains bad data (float32 size of %v)" , size )
232
230
}
233
- value , newOffset , err := d .decodeFloat32 (size , offset )
234
- if err != nil {
235
- return 0 , err
236
- }
231
+ value , newOffset := d .decodeFloat32 (size , offset )
237
232
238
233
switch result .Kind () {
239
234
case reflect .Float32 , reflect .Float64 :
@@ -253,10 +248,8 @@ func (d *decoder) unmarshalFloat64(size uint, offset uint, result reflect.Value)
253
248
if size != 8 {
254
249
return 0 , newInvalidDatabaseError ("the MaxMind DB file's data section contains bad data (float 64 size of %v)" , size )
255
250
}
256
- value , newOffset , err := d .decodeFloat64 (size , offset )
257
- if err != nil {
258
- return 0 , err
259
- }
251
+ value , newOffset := d .decodeFloat64 (size , offset )
252
+
260
253
switch result .Kind () {
261
254
case reflect .Float32 , reflect .Float64 :
262
255
if result .OverflowFloat (value ) {
@@ -277,10 +270,7 @@ func (d *decoder) unmarshalInt32(size uint, offset uint, result reflect.Value) (
277
270
if size > 4 {
278
271
return 0 , newInvalidDatabaseError ("the MaxMind DB file's data section contains bad data (int32 size of %v)" , size )
279
272
}
280
- value , newOffset , err := d .decodeInt (size , offset )
281
- if err != nil {
282
- return 0 , err
283
- }
273
+ value , newOffset := d .decodeInt (size , offset )
284
274
285
275
switch result .Kind () {
286
276
case reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 :
@@ -360,11 +350,8 @@ func (d *decoder) unmarshalSlice(
360
350
}
361
351
362
352
func (d * decoder ) unmarshalString (size uint , offset uint , result reflect.Value ) (uint , error ) {
363
- value , newOffset , err := d .decodeString (size , offset )
353
+ value , newOffset := d .decodeString (size , offset )
364
354
365
- if err != nil {
366
- return 0 , err
367
- }
368
355
switch result .Kind () {
369
356
case reflect .String :
370
357
result .SetString (value )
@@ -384,10 +371,7 @@ func (d *decoder) unmarshalUint(size uint, offset uint, result reflect.Value, ui
384
371
return 0 , newInvalidDatabaseError ("the MaxMind DB file's data section contains bad data (uint%v size of %v)" , uintType , size )
385
372
}
386
373
387
- value , newOffset , err := d .decodeUint (size , offset )
388
- if err != nil {
389
- return 0 , err
390
- }
374
+ value , newOffset := d .decodeUint (size , offset )
391
375
392
376
switch result .Kind () {
393
377
case reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 :
@@ -416,10 +400,7 @@ func (d *decoder) unmarshalUint128(size uint, offset uint, result reflect.Value)
416
400
if size > 16 {
417
401
return 0 , newInvalidDatabaseError ("the MaxMind DB file's data section contains bad data (uint128 size of %v)" , size )
418
402
}
419
- value , newOffset , err := d .decodeUint128 (size , offset )
420
- if err != nil {
421
- return 0 , err
422
- }
403
+ value , newOffset := d .decodeUint128 (size , offset )
423
404
424
405
switch result .Kind () {
425
406
case reflect .Struct :
@@ -436,36 +417,36 @@ func (d *decoder) unmarshalUint128(size uint, offset uint, result reflect.Value)
436
417
return newOffset , newUnmarshalTypeError (value , result .Type ())
437
418
}
438
419
439
- func (d * decoder ) decodeBool (size uint , offset uint ) (bool , uint , error ) {
440
- return size != 0 , offset , nil
420
+ func (d * decoder ) decodeBool (size uint , offset uint ) (bool , uint ) {
421
+ return size != 0 , offset
441
422
}
442
423
443
- func (d * decoder ) decodeBytes (size uint , offset uint ) ([]byte , uint , error ) {
424
+ func (d * decoder ) decodeBytes (size uint , offset uint ) ([]byte , uint ) {
444
425
newOffset := offset + size
445
426
bytes := make ([]byte , size )
446
427
copy (bytes , d .buffer [offset :newOffset ])
447
- return bytes , newOffset , nil
428
+ return bytes , newOffset
448
429
}
449
430
450
- func (d * decoder ) decodeFloat64 (size uint , offset uint ) (float64 , uint , error ) {
431
+ func (d * decoder ) decodeFloat64 (size uint , offset uint ) (float64 , uint ) {
451
432
newOffset := offset + size
452
433
bits := binary .BigEndian .Uint64 (d .buffer [offset :newOffset ])
453
- return math .Float64frombits (bits ), newOffset , nil
434
+ return math .Float64frombits (bits ), newOffset
454
435
}
455
436
456
- func (d * decoder ) decodeFloat32 (size uint , offset uint ) (float32 , uint , error ) {
437
+ func (d * decoder ) decodeFloat32 (size uint , offset uint ) (float32 , uint ) {
457
438
newOffset := offset + size
458
439
bits := binary .BigEndian .Uint32 (d .buffer [offset :newOffset ])
459
- return math .Float32frombits (bits ), newOffset , nil
440
+ return math .Float32frombits (bits ), newOffset
460
441
}
461
442
462
- func (d * decoder ) decodeInt (size uint , offset uint ) (int , uint , error ) {
443
+ func (d * decoder ) decodeInt (size uint , offset uint ) (int , uint ) {
463
444
newOffset := offset + size
464
445
var val int32
465
446
for _ , b := range d .buffer [offset :newOffset ] {
466
447
val = (val << 8 ) | int32 (b )
467
448
}
468
- return int (val ), newOffset , nil
449
+ return int (val ), newOffset
469
450
}
470
451
471
452
func (d * decoder ) decodeMap (
@@ -511,7 +492,7 @@ func (d *decoder) decodePointer(
511
492
if pointerSize == 4 {
512
493
prefix = 0
513
494
} else {
514
- prefix = uint ( size & 0x7 )
495
+ prefix = size & 0x7
515
496
}
516
497
unpacked := uintFromBytes (prefix , pointerBytes )
517
498
@@ -549,9 +530,9 @@ func (d *decoder) decodeSlice(
549
530
return offset , nil
550
531
}
551
532
552
- func (d * decoder ) decodeString (size uint , offset uint ) (string , uint , error ) {
533
+ func (d * decoder ) decodeString (size uint , offset uint ) (string , uint ) {
553
534
newOffset := offset + size
554
- return string (d .buffer [offset :newOffset ]), newOffset , nil
535
+ return string (d .buffer [offset :newOffset ]), newOffset
555
536
}
556
537
557
538
type fieldsType struct {
@@ -638,23 +619,23 @@ func (d *decoder) decodeStruct(
638
619
return offset , nil
639
620
}
640
621
641
- func (d * decoder ) decodeUint (size uint , offset uint ) (uint64 , uint , error ) {
622
+ func (d * decoder ) decodeUint (size uint , offset uint ) (uint64 , uint ) {
642
623
newOffset := offset + size
643
624
bytes := d .buffer [offset :newOffset ]
644
625
645
626
var val uint64
646
627
for _ , b := range bytes {
647
628
val = (val << 8 ) | uint64 (b )
648
629
}
649
- return val , newOffset , nil
630
+ return val , newOffset
650
631
}
651
632
652
- func (d * decoder ) decodeUint128 (size uint , offset uint ) (* big.Int , uint , error ) {
633
+ func (d * decoder ) decodeUint128 (size uint , offset uint ) (* big.Int , uint ) {
653
634
newOffset := offset + size
654
635
val := new (big.Int )
655
636
val .SetBytes (d .buffer [offset :newOffset ])
656
637
657
- return val , newOffset , nil
638
+ return val , newOffset
658
639
}
659
640
660
641
func uintFromBytes (prefix uint , uintBytes []byte ) uint {
0 commit comments