@@ -162,6 +162,59 @@ func (s *MySuite) TestDecoder(c *C) {
162162 c .Assert (reader .Close (), IsNil )
163163}
164164
165+ type PointerMap struct {
166+ MapX map [string ]interface {} `maxminddb:"mapX"`
167+ }
168+
169+ type TestPointerType struct {
170+ Array * []uint `maxminddb:"array"`
171+ Boolean * bool `maxminddb:"boolean"`
172+ Bytes * []byte `maxminddb:"bytes"`
173+ Double * float64 `maxminddb:"double"`
174+ Float * float32 `maxminddb:"float"`
175+ Int32 * int32 `maxminddb:"int32"`
176+ Map * PointerMap `maxminddb:"map"`
177+ Uint16 * uint16 `maxminddb:"uint16"`
178+ Uint32 * uint32 `maxminddb:"uint32"`
179+ Uint64 * uint64 `maxminddb:"uint64"`
180+ Uint128 * big.Int `maxminddb:"uint128"`
181+ Utf8String * string `maxminddb:"utf8_string"`
182+ }
183+
184+ func (s * MySuite ) TestStructWithPointer (c * C ) {
185+ reader , err := Open ("test-data/test-data/MaxMind-DB-test-decoder.mmdb" )
186+ c .Assert (err , IsNil )
187+
188+ var result TestPointerType
189+
190+ c .Log ("Before" )
191+ reader .Lookup (net .ParseIP ("::1.1.1.0" ), & result )
192+ c .Assert (err , IsNil )
193+
194+ c .Assert (* result .Array , DeepEquals , []uint {uint (1 ), uint (2 ), uint (3 )})
195+ c .Assert (* result .Boolean , Equals , true )
196+ c .Assert (* result .Bytes , DeepEquals , []byte {0x00 , 0x00 , 0x00 , 0x2a })
197+ c .Assert (* result .Double , Equals , 42.123456 )
198+ c .Assert (* result .Float , Equals , float32 (1.1 ))
199+ c .Assert (* result .Int32 , Equals , int32 (- 268435456 ))
200+
201+ c .Assert (result .Map .MapX , DeepEquals ,
202+ map [string ]interface {}{
203+ "arrayX" : []interface {}{uint64 (7 ), uint64 (8 ), uint64 (9 )},
204+ "utf8_stringX" : "hello" ,
205+ })
206+
207+ c .Assert (* result .Uint16 , Equals , uint16 (100 ))
208+ c .Assert (* result .Uint32 , Equals , uint32 (268435456 ))
209+ c .Assert (* result .Uint64 , Equals , uint64 (1152921504606846976 ))
210+ c .Assert (* result .Utf8String , Equals , "unicode! ☯ - ♫" )
211+ bigInt := new (big.Int )
212+ bigInt .SetString ("1329227995784915872903807060280344576" , 10 )
213+ c .Assert (result .Uint128 , DeepEquals , bigInt )
214+
215+ c .Assert (reader .Close (), IsNil )
216+ }
217+
165218func (s * MySuite ) TestNestedOffsetDecode (c * C ) {
166219 db , err := Open ("test-data/test-data/GeoIP2-City-Test.mmdb" )
167220 c .Assert (err , IsNil )
0 commit comments