generateMapKeyReadIndented generates code to read a map key with custom indentation
(buf *bytes.Buffer, keyType types.Type, varName string, indent string)
| 1026 | |
| 1027 | // generateMapKeyReadIndented generates code to read a map key with custom indentation |
| 1028 | func generateMapKeyReadIndented(buf *bytes.Buffer, keyType types.Type, varName string, indent string) error { |
| 1029 | if basic, ok := keyType.Underlying().(*types.Basic); ok { |
| 1030 | switch basic.Kind() { |
| 1031 | case types.Int: |
| 1032 | fmt.Fprintf(buf, "%s%s = int(buf.ReadInt64(err))\n", indent, varName) |
| 1033 | case types.String: |
| 1034 | fmt.Fprintf(buf, "%s%s = ctx.ReadString()\n", indent, varName) |
| 1035 | default: |
| 1036 | return fmt.Errorf("unsupported map key type: %v", keyType) |
| 1037 | } |
| 1038 | return nil |
| 1039 | } |
| 1040 | fmt.Fprintf(buf, "%sctx.ReadValue(reflect.ValueOf(&%s).Elem(), fory.RefModeTracking, true)\n", indent, varName) |
| 1041 | return nil |
| 1042 | } |
| 1043 | |
| 1044 | // generateMapValueReadIndented generates code to read a map value with custom indentation |
| 1045 | func generateMapValueReadIndented(buf *bytes.Buffer, valueType types.Type, varName string, indent string) error { |
no test coverage detected