generateMapKeyWriteIndented generates code to write a map key with custom indentation
(buf *bytes.Buffer, keyType types.Type, varName string, indent string)
| 783 | |
| 784 | // generateMapKeyWriteIndented generates code to write a map key with custom indentation |
| 785 | func generateMapKeyWriteIndented(buf *bytes.Buffer, keyType types.Type, varName string, indent string) error { |
| 786 | // For basic types, match reflection's serializer behavior |
| 787 | if basic, ok := keyType.Underlying().(*types.Basic); ok { |
| 788 | switch basic.Kind() { |
| 789 | case types.Int: |
| 790 | // intSerializer uses WriteInt64, not WriteVarint64 |
| 791 | fmt.Fprintf(buf, "%sbuf.WriteInt64(int64(%s))\n", indent, varName) |
| 792 | case types.String: |
| 793 | // stringSerializer.NeedWriteRef() = false, write directly |
| 794 | fmt.Fprintf(buf, "%sctx.WriteString(%s)\n", indent, varName) |
| 795 | default: |
| 796 | return fmt.Errorf("unsupported map key type: %v", keyType) |
| 797 | } |
| 798 | return nil |
| 799 | } |
| 800 | |
| 801 | // For other types, use WriteValue |
| 802 | fmt.Fprintf(buf, "%sctx.WriteValue(reflect.ValueOf(%s), fory.RefModeTracking, true)\n", indent, varName) |
| 803 | return nil |
| 804 | } |
| 805 | |
| 806 | // generateMapValueWriteIndented generates code to write a map value with custom indentation |
| 807 | func generateMapValueWriteIndented(buf *bytes.Buffer, valueType types.Type, varName string, indent string) error { |
no test coverage detected