MCPcopy Create free account
hub / github.com/apache/fory / generateMapValueWriteIndented

Function generateMapValueWriteIndented

go/fory/codegen/encoder.go:807–826  ·  view source on GitHub ↗

generateMapValueWriteIndented generates code to write a map value with custom indentation

(buf *bytes.Buffer, valueType types.Type, varName string, indent string)

Source from the content-addressed store, hash-verified

805
806// generateMapValueWriteIndented generates code to write a map value with custom indentation
807func generateMapValueWriteIndented(buf *bytes.Buffer, valueType types.Type, varName string, indent string) error {
808 // For basic types, match reflection's serializer behavior
809 if basic, ok := valueType.Underlying().(*types.Basic); ok {
810 switch basic.Kind() {
811 case types.Int:
812 // intSerializer uses WriteInt64, not WriteVarint64
813 fmt.Fprintf(buf, "%sbuf.WriteInt64(int64(%s))\n", indent, varName)
814 case types.String:
815 // stringSerializer.NeedWriteRef() = false, write directly
816 fmt.Fprintf(buf, "%sctx.WriteString(%s)\n", indent, varName)
817 default:
818 return fmt.Errorf("unsupported map value type: %v", valueType)
819 }
820 return nil
821 }
822
823 // For other types, use WriteValue
824 fmt.Fprintf(buf, "%sctx.WriteValue(reflect.ValueOf(%s), fory.RefModeTracking, true)\n", indent, varName)
825 return nil
826}
827
828// generateElementTypeIDWriteInline generates element type ID write with specific indentation
829func generateElementTypeIDWriteInline(buf *bytes.Buffer, elemType types.Type) error {

Callers 1

writeMapChunksCodeFunction · 0.85

Calls 1

KindMethod · 0.80

Tested by

no test coverage detected