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

Function generateMapReadInlineNoNull

go/fory/codegen/decoder.go:867–895  ·  view source on GitHub ↗
(buf *bytes.Buffer, mapType *types.Map, fieldAccess string)

Source from the content-addressed store, hash-verified

865}
866
867func generateMapReadInlineNoNull(buf *bytes.Buffer, mapType *types.Map, fieldAccess string) error {
868 keyType := mapType.Key()
869 valueType := mapType.Elem()
870
871 keyIsInterface := false
872 valueIsInterface := false
873 unwrappedKey := types.Unalias(keyType)
874 unwrappedValue := types.Unalias(valueType)
875 if iface, ok := unwrappedKey.(*types.Interface); ok && iface.Empty() {
876 keyIsInterface = true
877 }
878 if iface, ok := unwrappedValue.(*types.Interface); ok && iface.Empty() {
879 valueIsInterface = true
880 }
881
882 indent := "\t\t\t"
883 fmt.Fprintf(buf, "%smapLen := ctx.ReadCollectionLength()\n", indent)
884 fmt.Fprintf(buf, "%sif ctx.HasError() {\n", indent)
885 fmt.Fprintf(buf, "%s\treturn ctx.TakeError()\n", indent)
886 fmt.Fprintf(buf, "%s}\n", indent)
887 fmt.Fprintf(buf, "%sif mapLen == 0 {\n", indent)
888 fmt.Fprintf(buf, "%s\t%s = make(%s)\n", indent, fieldAccess, mapType.String())
889 fmt.Fprintf(buf, "%s} else {\n", indent)
890 if err := writeMapReadChunks(buf, mapType, fieldAccess, keyType, valueType, keyIsInterface, valueIsInterface, indent+"\t"); err != nil {
891 return err
892 }
893 fmt.Fprintf(buf, "%s}\n", indent)
894 return nil
895}
896
897// writeMapReadChunks generates the map chunk reading code with specified indentation
898func writeMapReadChunks(buf *bytes.Buffer, mapType *types.Map, fieldAccess string, keyType, valueType types.Type, keyIsInterface, valueIsInterface bool, indent string) error {

Callers 1

generateOptionValueReadFunction · 0.85

Calls 3

writeMapReadChunksFunction · 0.85
EmptyMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected