@@ -107,7 +107,7 @@ func (k Kind) IsScalar() bool {
107
107
// DataDecoder is a decoder for the MMDB data section.
108
108
// This is exported so mmdbdata package can use it, but still internal.
109
109
type DataDecoder struct {
110
- stringCache * StringCache
110
+ stringCache * stringCache
111
111
buffer []byte
112
112
}
113
113
@@ -120,17 +120,17 @@ const (
120
120
func NewDataDecoder (buffer []byte ) DataDecoder {
121
121
return DataDecoder {
122
122
buffer : buffer ,
123
- stringCache : NewStringCache (),
123
+ stringCache : newStringCache (),
124
124
}
125
125
}
126
126
127
- // Buffer returns the underlying buffer for direct access.
128
- func (d * DataDecoder ) Buffer () []byte {
127
+ // getBuffer returns the underlying buffer for direct access.
128
+ func (d * DataDecoder ) getBuffer () []byte {
129
129
return d .buffer
130
130
}
131
131
132
- // DecodeCtrlData decodes the control byte and data info at the given offset.
133
- func (d * DataDecoder ) DecodeCtrlData (offset uint ) (Kind , uint , uint , error ) {
132
+ // decodeCtrlData decodes the control byte and data info at the given offset.
133
+ func (d * DataDecoder ) decodeCtrlData (offset uint ) (Kind , uint , uint , error ) {
134
134
newOffset := offset + 1
135
135
if offset >= uint (len (d .buffer )) {
136
136
return 0 , 0 , 0 , mmdberrors .NewOffsetError ()
@@ -151,8 +151,8 @@ func (d *DataDecoder) DecodeCtrlData(offset uint) (Kind, uint, uint, error) {
151
151
return kindNum , size , newOffset , err
152
152
}
153
153
154
- // DecodeBytes decodes a byte slice from the given offset with the given size.
155
- func (d * DataDecoder ) DecodeBytes (size , offset uint ) ([]byte , uint , error ) {
154
+ // decodeBytes decodes a byte slice from the given offset with the given size.
155
+ func (d * DataDecoder ) decodeBytes (size , offset uint ) ([]byte , uint , error ) {
156
156
if offset + size > uint (len (d .buffer )) {
157
157
return nil , 0 , mmdberrors .NewOffsetError ()
158
158
}
@@ -164,7 +164,7 @@ func (d *DataDecoder) DecodeBytes(size, offset uint) ([]byte, uint, error) {
164
164
}
165
165
166
166
// DecodeFloat64 decodes a 64-bit float from the given offset.
167
- func (d * DataDecoder ) DecodeFloat64 (size , offset uint ) (float64 , uint , error ) {
167
+ func (d * DataDecoder ) decodeFloat64 (size , offset uint ) (float64 , uint , error ) {
168
168
if size != 8 {
169
169
return 0 , 0 , mmdberrors .NewInvalidDatabaseError (
170
170
"the MaxMind DB file's data section contains bad data (float 64 size of %v)" ,
@@ -181,7 +181,7 @@ func (d *DataDecoder) DecodeFloat64(size, offset uint) (float64, uint, error) {
181
181
}
182
182
183
183
// DecodeFloat32 decodes a 32-bit float from the given offset.
184
- func (d * DataDecoder ) DecodeFloat32 (size , offset uint ) (float32 , uint , error ) {
184
+ func (d * DataDecoder ) decodeFloat32 (size , offset uint ) (float32 , uint , error ) {
185
185
if size != 4 {
186
186
return 0 , 0 , mmdberrors .NewInvalidDatabaseError (
187
187
"the MaxMind DB file's data section contains bad data (float32 size of %v)" ,
@@ -198,7 +198,7 @@ func (d *DataDecoder) DecodeFloat32(size, offset uint) (float32, uint, error) {
198
198
}
199
199
200
200
// DecodeInt32 decodes a 32-bit signed integer from the given offset.
201
- func (d * DataDecoder ) DecodeInt32 (size , offset uint ) (int32 , uint , error ) {
201
+ func (d * DataDecoder ) decodeInt32 (size , offset uint ) (int32 , uint , error ) {
202
202
if size > 4 {
203
203
return 0 , 0 , mmdberrors .NewInvalidDatabaseError (
204
204
"the MaxMind DB file's data section contains bad data (int32 size of %v)" ,
@@ -218,7 +218,7 @@ func (d *DataDecoder) DecodeInt32(size, offset uint) (int32, uint, error) {
218
218
}
219
219
220
220
// DecodePointer decodes a pointer from the given offset.
221
- func (d * DataDecoder ) DecodePointer (
221
+ func (d * DataDecoder ) decodePointer (
222
222
size uint ,
223
223
offset uint ,
224
224
) (uint , uint , error ) {
@@ -254,7 +254,7 @@ func (d *DataDecoder) DecodePointer(
254
254
}
255
255
256
256
// DecodeBool decodes a boolean from the given offset.
257
- func (* DataDecoder ) DecodeBool (size , offset uint ) (bool , uint , error ) {
257
+ func (* DataDecoder ) decodeBool (size , offset uint ) (bool , uint , error ) {
258
258
if size > 1 {
259
259
return false , 0 , mmdberrors .NewInvalidDatabaseError (
260
260
"the MaxMind DB file's data section contains bad data (bool size of %v)" ,
@@ -266,18 +266,18 @@ func (*DataDecoder) DecodeBool(size, offset uint) (bool, uint, error) {
266
266
}
267
267
268
268
// DecodeString decodes a string from the given offset.
269
- func (d * DataDecoder ) DecodeString (size , offset uint ) (string , uint , error ) {
269
+ func (d * DataDecoder ) decodeString (size , offset uint ) (string , uint , error ) {
270
270
if offset + size > uint (len (d .buffer )) {
271
271
return "" , 0 , mmdberrors .NewOffsetError ()
272
272
}
273
273
274
274
newOffset := offset + size
275
- value := d .stringCache .InternAt (offset , size , d .buffer )
275
+ value := d .stringCache .internAt (offset , size , d .buffer )
276
276
return value , newOffset , nil
277
277
}
278
278
279
279
// DecodeUint16 decodes a 16-bit unsigned integer from the given offset.
280
- func (d * DataDecoder ) DecodeUint16 (size , offset uint ) (uint16 , uint , error ) {
280
+ func (d * DataDecoder ) decodeUint16 (size , offset uint ) (uint16 , uint , error ) {
281
281
if size > 2 {
282
282
return 0 , 0 , mmdberrors .NewInvalidDatabaseError (
283
283
"the MaxMind DB file's data section contains bad data (uint16 size of %v)" ,
@@ -299,7 +299,7 @@ func (d *DataDecoder) DecodeUint16(size, offset uint) (uint16, uint, error) {
299
299
}
300
300
301
301
// DecodeUint32 decodes a 32-bit unsigned integer from the given offset.
302
- func (d * DataDecoder ) DecodeUint32 (size , offset uint ) (uint32 , uint , error ) {
302
+ func (d * DataDecoder ) decodeUint32 (size , offset uint ) (uint32 , uint , error ) {
303
303
if size > 4 {
304
304
return 0 , 0 , mmdberrors .NewInvalidDatabaseError (
305
305
"the MaxMind DB file's data section contains bad data (uint32 size of %v)" ,
@@ -321,7 +321,7 @@ func (d *DataDecoder) DecodeUint32(size, offset uint) (uint32, uint, error) {
321
321
}
322
322
323
323
// DecodeUint64 decodes a 64-bit unsigned integer from the given offset.
324
- func (d * DataDecoder ) DecodeUint64 (size , offset uint ) (uint64 , uint , error ) {
324
+ func (d * DataDecoder ) decodeUint64 (size , offset uint ) (uint64 , uint , error ) {
325
325
if size > 8 {
326
326
return 0 , 0 , mmdberrors .NewInvalidDatabaseError (
327
327
"the MaxMind DB file's data section contains bad data (uint64 size of %v)" ,
@@ -344,7 +344,7 @@ func (d *DataDecoder) DecodeUint64(size, offset uint) (uint64, uint, error) {
344
344
345
345
// DecodeUint128 decodes a 128-bit unsigned integer from the given offset.
346
346
// Returns the value as high and low 64-bit unsigned integers.
347
- func (d * DataDecoder ) DecodeUint128 (size , offset uint ) (hi , lo uint64 , newOffset uint , err error ) {
347
+ func (d * DataDecoder ) decodeUint128 (size , offset uint ) (hi , lo uint64 , newOffset uint , err error ) {
348
348
if size > 16 {
349
349
return 0 , 0 , 0 , mmdberrors .NewInvalidDatabaseError (
350
350
"the MaxMind DB file's data section contains bad data (uint128 size of %v)" ,
@@ -375,17 +375,17 @@ func append64(val uint64, b byte) (uint64, byte) {
375
375
// can take advantage of https://github.com/golang/go/issues/3512 to avoid
376
376
// copying the bytes when decoding a struct. Previously, we achieved this by
377
377
// using unsafe.
378
- func (d * DataDecoder ) DecodeKey (offset uint ) ([]byte , uint , error ) {
379
- kindNum , size , dataOffset , err := d .DecodeCtrlData (offset )
378
+ func (d * DataDecoder ) decodeKey (offset uint ) ([]byte , uint , error ) {
379
+ kindNum , size , dataOffset , err := d .decodeCtrlData (offset )
380
380
if err != nil {
381
381
return nil , 0 , err
382
382
}
383
383
if kindNum == KindPointer {
384
- pointer , ptrOffset , err := d .DecodePointer (size , dataOffset )
384
+ pointer , ptrOffset , err := d .decodePointer (size , dataOffset )
385
385
if err != nil {
386
386
return nil , 0 , err
387
387
}
388
- key , _ , err := d .DecodeKey (pointer )
388
+ key , _ , err := d .decodeKey (pointer )
389
389
return key , ptrOffset , err
390
390
}
391
391
if kindNum != KindString {
@@ -404,17 +404,17 @@ func (d *DataDecoder) DecodeKey(offset uint) ([]byte, uint, error) {
404
404
// NextValueOffset skips ahead to the next value without decoding
405
405
// the one at the offset passed in. The size bits have different meanings for
406
406
// different data types.
407
- func (d * DataDecoder ) NextValueOffset (offset , numberToSkip uint ) (uint , error ) {
407
+ func (d * DataDecoder ) nextValueOffset (offset , numberToSkip uint ) (uint , error ) {
408
408
if numberToSkip == 0 {
409
409
return offset , nil
410
410
}
411
- kindNum , size , offset , err := d .DecodeCtrlData (offset )
411
+ kindNum , size , offset , err := d .decodeCtrlData (offset )
412
412
if err != nil {
413
413
return 0 , err
414
414
}
415
415
switch kindNum {
416
416
case KindPointer :
417
- _ , offset , err = d .DecodePointer (size , offset )
417
+ _ , offset , err = d .decodePointer (size , offset )
418
418
if err != nil {
419
419
return 0 , err
420
420
}
@@ -426,7 +426,7 @@ func (d *DataDecoder) NextValueOffset(offset, numberToSkip uint) (uint, error) {
426
426
default :
427
427
offset += size
428
428
}
429
- return d .NextValueOffset (offset , numberToSkip - 1 )
429
+ return d .nextValueOffset (offset , numberToSkip - 1 )
430
430
}
431
431
432
432
func (d * DataDecoder ) sizeFromCtrlByte (
0 commit comments