(buf *bytes.Buffer, sliceType *types.Slice, fieldAccess string)
| 535 | } |
| 536 | |
| 537 | func generateSliceReadInlineNoNull(buf *bytes.Buffer, sliceType *types.Slice, fieldAccess string) error { |
| 538 | elemType := sliceType.Elem() |
| 539 | indent := "\t\t\t" |
| 540 | |
| 541 | unwrappedElem := types.Unalias(elemType) |
| 542 | if iface, ok := unwrappedElem.(*types.Interface); ok && iface.Empty() { |
| 543 | fmt.Fprintf(buf, "%s// Dynamic slice []any handling - no null flag\n", indent) |
| 544 | fmt.Fprintf(buf, "%ssliceLen := ctx.ReadCollectionLength()\n", indent) |
| 545 | fmt.Fprintf(buf, "%sif ctx.HasError() {\n", indent) |
| 546 | fmt.Fprintf(buf, "%s\treturn ctx.TakeError()\n", indent) |
| 547 | fmt.Fprintf(buf, "%s}\n", indent) |
| 548 | fmt.Fprintf(buf, "%sif sliceLen == 0 {\n", indent) |
| 549 | fmt.Fprintf(buf, "%s\t%s = make([]any, 0)\n", indent, fieldAccess) |
| 550 | fmt.Fprintf(buf, "%s} else {\n", indent) |
| 551 | fmt.Fprintf(buf, "%s\t_ = buf.ReadInt8(err) // collection flags\n", indent) |
| 552 | fmt.Fprintf(buf, "%s\tif ctx.HasError() {\n", indent) |
| 553 | fmt.Fprintf(buf, "%s\t\treturn ctx.TakeError()\n", indent) |
| 554 | fmt.Fprintf(buf, "%s\t}\n", indent) |
| 555 | fmt.Fprintf(buf, "%s\tif !buf.CheckReadable(sliceLen, err) {\n", indent) |
| 556 | fmt.Fprintf(buf, "%s\t\treturn ctx.TakeError()\n", indent) |
| 557 | fmt.Fprintf(buf, "%s\t}\n", indent) |
| 558 | fmt.Fprintf(buf, "%s\t%s = make([]any, sliceLen)\n", indent, fieldAccess) |
| 559 | fmt.Fprintf(buf, "%s\tfor i := range %s {\n", indent, fieldAccess) |
| 560 | fmt.Fprintf(buf, "%s\t\tctx.ReadValue(reflect.ValueOf(&%s[i]).Elem(), fory.RefModeTracking, true)\n", indent, fieldAccess) |
| 561 | fmt.Fprintf(buf, "%s\t}\n", indent) |
| 562 | fmt.Fprintf(buf, "%s}\n", indent) |
| 563 | return nil |
| 564 | } |
| 565 | |
| 566 | elemIsReferencable := isReferencableType(elemType) |
| 567 | fmt.Fprintf(buf, "%ssliceLen := ctx.ReadCollectionLength()\n", indent) |
| 568 | fmt.Fprintf(buf, "%sif ctx.HasError() {\n", indent) |
| 569 | fmt.Fprintf(buf, "%s\treturn ctx.TakeError()\n", indent) |
| 570 | fmt.Fprintf(buf, "%s}\n", indent) |
| 571 | fmt.Fprintf(buf, "%sif sliceLen == 0 {\n", indent) |
| 572 | fmt.Fprintf(buf, "%s\t%s = make(%s, 0)\n", indent, fieldAccess, sliceType.String()) |
| 573 | fmt.Fprintf(buf, "%s} else {\n", indent) |
| 574 | if err := writeSliceReadElements(buf, sliceType, elemType, fieldAccess, elemIsReferencable, indent+"\t"); err != nil { |
| 575 | return err |
| 576 | } |
| 577 | fmt.Fprintf(buf, "%s}\n", indent) |
| 578 | return nil |
| 579 | } |
| 580 | |
| 581 | // writeSliceReadElements generates the element reading code for a slice with specified indentation |
| 582 | func writeSliceReadElements(buf *bytes.Buffer, sliceType *types.Slice, elemType types.Type, fieldAccess string, elemIsReferencable bool, indent string) error { |
no test coverage detected