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

Function generateSliceElementReadDirectIndented

go/fory/codegen/decoder.go:770–804  ·  view source on GitHub ↗

generateSliceElementReadDirectIndented generates code to read slice elements directly with custom indentation

(buf *bytes.Buffer, elemType types.Type, elemAccess string, indent string)

Source from the content-addressed store, hash-verified

768
769// generateSliceElementReadDirectIndented generates code to read slice elements directly with custom indentation
770func generateSliceElementReadDirectIndented(buf *bytes.Buffer, elemType types.Type, elemAccess string, indent string) error {
771 if basic, ok := elemType.Underlying().(*types.Basic); ok {
772 switch basic.Kind() {
773 case types.Bool:
774 fmt.Fprintf(buf, "%s%s = buf.ReadBool(err)\n", indent, elemAccess)
775 case types.Int8:
776 fmt.Fprintf(buf, "%s%s = buf.ReadInt8(err)\n", indent, elemAccess)
777 case types.Int16:
778 fmt.Fprintf(buf, "%s%s = buf.ReadInt16(err)\n", indent, elemAccess)
779 case types.Int32:
780 fmt.Fprintf(buf, "%s%s = buf.ReadVarint32(err)\n", indent, elemAccess)
781 case types.Int, types.Int64:
782 fmt.Fprintf(buf, "%s%s = buf.ReadVarint64(err)\n", indent, elemAccess)
783 case types.Uint8:
784 fmt.Fprintf(buf, "%s%s = buf.ReadByte(err)\n", indent, elemAccess)
785 case types.Uint16:
786 fmt.Fprintf(buf, "%s%s = uint16(buf.ReadInt16(err))\n", indent, elemAccess)
787 case types.Uint32:
788 fmt.Fprintf(buf, "%s%s = uint32(buf.ReadInt32(err))\n", indent, elemAccess)
789 case types.Uint, types.Uint64:
790 fmt.Fprintf(buf, "%s%s = uint64(buf.ReadInt64(err))\n", indent, elemAccess)
791 case types.Float32:
792 fmt.Fprintf(buf, "%s%s = buf.ReadFloat32(err)\n", indent, elemAccess)
793 case types.Float64:
794 fmt.Fprintf(buf, "%s%s = buf.ReadFloat64(err)\n", indent, elemAccess)
795 case types.String:
796 fmt.Fprintf(buf, "%s%s = ctx.ReadString()\n", indent, elemAccess)
797 default:
798 return fmt.Errorf("unsupported basic type for direct element read: %s", basic.String())
799 }
800 return nil
801 }
802
803 return fmt.Errorf("unsupported element type for direct read: %s", elemType.String())
804}
805
806// generateMapReadInline generates inline map deserialization code following the chunk-based format
807// Uses error-aware methods for deferred error checking

Callers 1

writeSliceReadElementsFunction · 0.85

Calls 2

KindMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected