(_map reflect.Value)
| 168 | } |
| 169 | |
| 170 | func (d *Decoder) decodeCompoundMap(_map reflect.Value) error { |
| 171 | var typeId [1]byte |
| 172 | for { |
| 173 | err := d.readTo(typeId[:]) |
| 174 | if err != nil { |
| 175 | return err |
| 176 | } |
| 177 | if typeId[0] == End { |
| 178 | return nil |
| 179 | } |
| 180 | |
| 181 | name, err := d.readString() |
| 182 | if err != nil { |
| 183 | return err |
| 184 | } |
| 185 | |
| 186 | nameVal := reflect.ValueOf(name) |
| 187 | switch typeId[0] { |
| 188 | case Byte: |
| 189 | d, err := d.readByte() |
| 190 | if err != nil { |
| 191 | return err |
| 192 | } |
| 193 | |
| 194 | switch _map.Type().Elem().Kind() { |
| 195 | case reflect.Uint8: |
| 196 | _map.SetMapIndex(nameVal, reflect.ValueOf(uint8(d))) |
| 197 | case reflect.Int8: |
| 198 | case reflect.Bool: |
| 199 | _map.SetMapIndex(nameVal, reflect.ValueOf(*(*bool)(unsafe.Pointer(&d)))) |
| 200 | default: |
| 201 | if reflect.TypeOf(d).AssignableTo(_map.Type().Elem()) { |
| 202 | _map.SetMapIndex(nameVal, reflect.ValueOf(d)) |
| 203 | } else { |
| 204 | if reflect.TypeOf(d).ConvertibleTo(_map.Type().Elem()) { |
| 205 | _map.SetMapIndex(nameVal, reflect.ValueOf(d).Convert(_map.Type().Elem())) |
| 206 | } else { |
| 207 | return fmt.Errorf("cannot assign byte to type %s for field %s", _map.Type().Elem(), name) |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | case Short: |
| 212 | d, err := d.readShort() |
| 213 | if err != nil { |
| 214 | return err |
| 215 | } |
| 216 | |
| 217 | switch _map.Type().Elem().Kind() { |
| 218 | case reflect.Uint16: |
| 219 | _map.SetMapIndex(nameVal, reflect.ValueOf(uint16(d))) |
| 220 | default: |
| 221 | if reflect.TypeOf(d).AssignableTo(_map.Type().Elem()) { |
| 222 | _map.SetMapIndex(nameVal, reflect.ValueOf(d)) |
| 223 | } else { |
| 224 | if reflect.TypeOf(d).ConvertibleTo(_map.Type().Elem()) { |
| 225 | _map.SetMapIndex(nameVal, reflect.ValueOf(d).Convert(_map.Type().Elem())) |
| 226 | } else { |
| 227 | return fmt.Errorf("cannot assign short to type %s for field %s", _map.Type().Elem(), name) |
no test coverage detected