(v reflect.Value)
| 370 | } |
| 371 | |
| 372 | func (m *MarshalBSUPContext) encodeMap(v reflect.Value) (super.Type, error) { |
| 373 | var lastKeyType, lastValType super.Type |
| 374 | m.Builder.BeginContainer() |
| 375 | for it := v.MapRange(); it.Next(); { |
| 376 | keyType, err := m.encodeValue(it.Key()) |
| 377 | if err != nil { |
| 378 | return nil, err |
| 379 | } |
| 380 | if keyType != lastKeyType && lastKeyType != nil { |
| 381 | return nil, errors.New("map has mixed key types") |
| 382 | } |
| 383 | lastKeyType = keyType |
| 384 | valType, err := m.encodeValue(it.Value()) |
| 385 | if err != nil { |
| 386 | return nil, err |
| 387 | } |
| 388 | if valType != lastValType && lastValType != nil { |
| 389 | return nil, errors.New("map has mixed values types") |
| 390 | } |
| 391 | lastValType = valType |
| 392 | } |
| 393 | m.Builder.TransformContainer(super.NormalizeMap) |
| 394 | m.Builder.EndContainer() |
| 395 | if lastKeyType == nil { |
| 396 | // Map is empty so look up types. |
| 397 | var err error |
| 398 | lastKeyType, err = m.lookupType(v.Type().Key()) |
| 399 | if err != nil { |
| 400 | return nil, err |
| 401 | } |
| 402 | lastValType, err = m.lookupType(v.Type().Elem()) |
| 403 | if err != nil { |
| 404 | return nil, err |
| 405 | } |
| 406 | } |
| 407 | return m.Context.LookupTypeMap(lastKeyType, lastValType), nil |
| 408 | } |
| 409 | |
| 410 | func (m *MarshalBSUPContext) encodeRecord(sval reflect.Value) (super.Type, error) { |
| 411 | m.Builder.BeginContainer() |
no test coverage detected