(buf *bytes.Buffer, mapType *types.Map, fieldAccess string)
| 592 | } |
| 593 | |
| 594 | func generateMapWriteInlineNoNull(buf *bytes.Buffer, mapType *types.Map, fieldAccess string) error { |
| 595 | keyType := mapType.Key() |
| 596 | valueType := mapType.Elem() |
| 597 | |
| 598 | keyIsInterface := false |
| 599 | valueIsInterface := false |
| 600 | unwrappedKey := types.Unalias(keyType) |
| 601 | unwrappedValue := types.Unalias(valueType) |
| 602 | if iface, ok := unwrappedKey.(*types.Interface); ok && iface.Empty() { |
| 603 | keyIsInterface = true |
| 604 | } |
| 605 | if iface, ok := unwrappedValue.(*types.Interface); ok && iface.Empty() { |
| 606 | valueIsInterface = true |
| 607 | } |
| 608 | |
| 609 | indent := "\t\t" |
| 610 | fmt.Fprintf(buf, "%smapLen := 0\n", indent) |
| 611 | fmt.Fprintf(buf, "%sif %s != nil {\n", indent, fieldAccess) |
| 612 | fmt.Fprintf(buf, "%s\tmapLen = len(%s)\n", indent, fieldAccess) |
| 613 | fmt.Fprintf(buf, "%s}\n", indent) |
| 614 | fmt.Fprintf(buf, "%sbuf.WriteVarUint32(uint32(mapLen))\n", indent) |
| 615 | |
| 616 | // Write map chunks without null flag (xlang style) |
| 617 | if err := writeMapChunksCode(buf, keyType, valueType, fieldAccess, keyIsInterface, valueIsInterface, indent); err != nil { |
| 618 | return err |
| 619 | } |
| 620 | |
| 621 | return nil |
| 622 | } |
| 623 | |
| 624 | // writeMapChunksCode generates the map chunk writing code with specified indentation |
| 625 | func writeMapChunksCode(buf *bytes.Buffer, keyType, valueType types.Type, fieldAccess string, keyIsInterface, valueIsInterface bool, indent string) error { |
no test coverage detected