in decode.go [190:236]
func (d *Decoder) decMapType() (reflect.Type, error) {
var (
err error
arr [1]byte
buf []byte
tag byte
idx int32
typ reflect.Type
typName string
)
buf = arr[:1]
if _, err = io.ReadFull(d.reader, buf); err != nil {
return nil, perrors.WithStack(err)
}
tag = buf[0]
if (tag >= BC_STRING_DIRECT && tag <= STRING_DIRECT_MAX) ||
(tag >= 0x30 && tag <= 0x33) || (tag == BC_STRING) || (tag == BC_STRING_CHUNK) {
typName, err = d.decString(int32(tag))
if err != nil {
return nil, perrors.WithStack(err)
}
info, ok := getStructInfo(typName)
if ok {
typ = info.typ
} else {
typ = reflect.TypeOf(map[interface{}]interface{}{})
}
// add to type map
d.typeRefs.appendTypeRefs(typName, typ)
return typ, nil
}
if idx, err = d.decInt32(int32(tag)); err != nil {
return nil, perrors.WithStack(err)
}
typ = d.typeRefs.Get(int(idx))
if typ == nil {
return nil, perrors.Errorf("the type ref index %d is out of range", idx)
}
return typ, err
}