(ctx *WriteContext, value reflect.Value)
| 76 | } |
| 77 | |
| 78 | func (s sliceDynSerializer) WriteData(ctx *WriteContext, value reflect.Value) { |
| 79 | buf := ctx.Buffer() |
| 80 | // Get slice length and handle empty slice case |
| 81 | length := value.Len() |
| 82 | if length == 0 { |
| 83 | buf.WriteVarUint32(0) // WriteData 0 for empty slice |
| 84 | return |
| 85 | } |
| 86 | |
| 87 | // WriteData collection header and get type information |
| 88 | collectFlag, elemTypeInfo := s.writeHeader(ctx, buf, value) |
| 89 | if ctx.HasError() { |
| 90 | return |
| 91 | } |
| 92 | |
| 93 | // Choose serialization path based on type consistency |
| 94 | if (collectFlag & CollectionIsSameType) != 0 { |
| 95 | s.writeSameType(ctx, buf, value, elemTypeInfo, collectFlag) // Optimized path for same-type elements |
| 96 | } else { |
| 97 | s.writeDifferentTypes(ctx, buf, value, collectFlag) // Fallback path for mixed-type elements |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // writeHeader prepares and writes collection metadata including: |
| 102 | // - Collection size |
no test coverage detected