writeDifferentTypes handles serialization of collections with mixed element types
(ctx *WriteContext, buf *ByteBuffer, keys []reflect.Value, flag byte)
| 261 | |
| 262 | // writeDifferentTypes handles serialization of collections with mixed element types |
| 263 | func (s setSerializer) writeDifferentTypes(ctx *WriteContext, buf *ByteBuffer, keys []reflect.Value, flag byte) { |
| 264 | trackRefs := (flag & CollectionTrackingRef) != 0 |
| 265 | hasNull := (flag & CollectionHasNull) != 0 |
| 266 | |
| 267 | for _, key := range keys { |
| 268 | key = UnwrapReflectValue(key) |
| 269 | if isNull(key) { |
| 270 | buf.WriteInt8(NullFlag) // WriteData null marker |
| 271 | continue |
| 272 | } |
| 273 | |
| 274 | // Get type info for each element (since types vary) |
| 275 | typeInfo, _ := ctx.TypeResolver().getTypeInfo(key, true) |
| 276 | |
| 277 | if trackRefs { |
| 278 | // Write ref flag, type ID, and data |
| 279 | refWritten, err := ctx.RefResolver().WriteRefOrNull(buf, key) |
| 280 | if err != nil { |
| 281 | ctx.SetError(FromError(err)) |
| 282 | return |
| 283 | } |
| 284 | ctx.TypeResolver().WriteTypeInfo(buf, typeInfo, ctx.Err()) |
| 285 | if !refWritten { |
| 286 | typeInfo.Serializer.WriteData(ctx, key) |
| 287 | if ctx.HasError() { |
| 288 | return |
| 289 | } |
| 290 | } |
| 291 | } else if hasNull { |
| 292 | // No ref tracking but may have nulls - write NotNullValueFlag before type + data |
| 293 | buf.WriteInt8(NotNullValueFlag) |
| 294 | ctx.TypeResolver().WriteTypeInfo(buf, typeInfo, ctx.Err()) |
| 295 | typeInfo.Serializer.WriteData(ctx, key) |
| 296 | if ctx.HasError() { |
| 297 | return |
| 298 | } |
| 299 | } else { |
| 300 | // No ref tracking and no nulls - write type + data directly |
| 301 | ctx.TypeResolver().WriteTypeInfo(buf, typeInfo, ctx.Err()) |
| 302 | typeInfo.Serializer.WriteData(ctx, key) |
| 303 | if ctx.HasError() { |
| 304 | return |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | // Read deserializes a set from the buffer into the provided reflect.Value |
| 311 | func (s setSerializer) ReadData(ctx *ReadContext, value reflect.Value) { |
no test coverage detected