(buf *bytes.Buffer, sliceType *types.Slice, fieldAccess string)
| 483 | } |
| 484 | |
| 485 | func generateSliceWriteInlineNoNull(buf *bytes.Buffer, sliceType *types.Slice, fieldAccess string) error { |
| 486 | elemType := sliceType.Elem() |
| 487 | indent := "\t\t" |
| 488 | |
| 489 | // Dynamic slice []any handling (no null flag) |
| 490 | unwrappedElem := types.Unalias(elemType) |
| 491 | if iface, ok := unwrappedElem.(*types.Interface); ok && iface.Empty() { |
| 492 | fmt.Fprintf(buf, "%s// Dynamic slice []any handling - no null flag\n", indent) |
| 493 | fmt.Fprintf(buf, "%ssliceLen := 0\n", indent) |
| 494 | fmt.Fprintf(buf, "%sif %s != nil {\n", indent, fieldAccess) |
| 495 | fmt.Fprintf(buf, "%s\tsliceLen = len(%s)\n", indent, fieldAccess) |
| 496 | fmt.Fprintf(buf, "%s}\n", indent) |
| 497 | fmt.Fprintf(buf, "%sbuf.WriteVarUint32(uint32(sliceLen))\n", indent) |
| 498 | fmt.Fprintf(buf, "%sif sliceLen > 0 {\n", indent) |
| 499 | fmt.Fprintf(buf, "%s\tbuf.WriteInt8(1) // CollectionTrackingRef only\n", indent) |
| 500 | fmt.Fprintf(buf, "%s\tfor _, elem := range %s {\n", indent, fieldAccess) |
| 501 | fmt.Fprintf(buf, "%s\t\tctx.WriteValue(reflect.ValueOf(elem), fory.RefModeTracking, true)\n", indent) |
| 502 | fmt.Fprintf(buf, "%s\t}\n", indent) |
| 503 | fmt.Fprintf(buf, "%s}\n", indent) |
| 504 | return nil |
| 505 | } |
| 506 | |
| 507 | // Slices use LIST protocol by default, including primitive element slices. |
| 508 | elemIsReferencable := isReferencableType(elemType) |
| 509 | fmt.Fprintf(buf, "%ssliceLen := 0\n", indent) |
| 510 | fmt.Fprintf(buf, "%sif %s != nil {\n", indent, fieldAccess) |
| 511 | fmt.Fprintf(buf, "%s\tsliceLen = len(%s)\n", indent, fieldAccess) |
| 512 | fmt.Fprintf(buf, "%s}\n", indent) |
| 513 | fmt.Fprintf(buf, "%sbuf.WriteVarUint32(uint32(sliceLen))\n", indent) |
| 514 | fmt.Fprintf(buf, "%sif sliceLen > 0 {\n", indent) |
| 515 | fmt.Fprintf(buf, "%s\tcollectFlag := 12 // CollectionIsSameType | CollectionIsDeclElementType\n", indent) |
| 516 | if elemIsReferencable { |
| 517 | fmt.Fprintf(buf, "%s\tif ctx.TrackRef() {\n", indent) |
| 518 | fmt.Fprintf(buf, "%s\t\tcollectFlag |= 1 // CollectionTrackingRef\n", indent) |
| 519 | fmt.Fprintf(buf, "%s\t}\n", indent) |
| 520 | } |
| 521 | fmt.Fprintf(buf, "%s\tbuf.WriteInt8(int8(collectFlag))\n", indent) |
| 522 | fmt.Fprintf(buf, "%s\tfor _, elem := range %s {\n", indent, fieldAccess) |
| 523 | if elemIsReferencable { |
| 524 | fmt.Fprintf(buf, "%s\t\tif ctx.TrackRef() {\n", indent) |
| 525 | fmt.Fprintf(buf, "%s\t\t\tbuf.WriteInt8(-1) // NotNullValueFlag for element\n", indent) |
| 526 | fmt.Fprintf(buf, "%s\t\t}\n", indent) |
| 527 | } |
| 528 | if err := generateSliceElementWriteInlineIndented(buf, elemType, "elem", indent+"\t\t"); err != nil { |
| 529 | return err |
| 530 | } |
| 531 | fmt.Fprintf(buf, "%s\t}\n", indent) |
| 532 | fmt.Fprintf(buf, "%s}\n", indent) |
| 533 | return nil |
| 534 | } |
| 535 | |
| 536 | // generateMapWriteInline generates inline map serialization code following the chunk-based format |
| 537 | func generateMapWriteInline(buf *bytes.Buffer, mapType *types.Map, fieldAccess string) error { |
no test coverage detected