readDifferentTypes handles deserialization of sets with mixed element types
(ctx *ReadContext, buf *ByteBuffer, value reflect.Value, length int, flag int8)
| 431 | |
| 432 | // readDifferentTypes handles deserialization of sets with mixed element types |
| 433 | func (s setSerializer) readDifferentTypes(ctx *ReadContext, buf *ByteBuffer, value reflect.Value, length int, flag int8) { |
| 434 | trackRefs := (flag & CollectionTrackingRef) != 0 |
| 435 | hasNull := (flag & CollectionHasNull) != 0 |
| 436 | keyType := value.Type().Key() |
| 437 | ctxErr := ctx.Err() |
| 438 | |
| 439 | for i := 0; i < length; i++ { |
| 440 | if trackRefs { |
| 441 | // Read with ref tracking: refFlag + typeId + data |
| 442 | refID, refErr := ctx.RefResolver().TryPreserveRefId(buf) |
| 443 | if refErr != nil { |
| 444 | ctx.SetError(FromError(refErr)) |
| 445 | return |
| 446 | } |
| 447 | if refID == int32(NullFlag) { |
| 448 | // Null element - skip for sets |
| 449 | continue |
| 450 | } |
| 451 | if refID < int32(NotNullValueFlag) { |
| 452 | // Use existing reference if available |
| 453 | elem := ctx.RefResolver().GetReadObject(refID) |
| 454 | value.SetMapIndex(elem, emptyStructVal) |
| 455 | continue |
| 456 | } |
| 457 | // Read type info (handles namespaced types, meta sharing, etc.) |
| 458 | typeInfo := ctx.TypeResolver().ReadTypeInfo(buf, ctxErr) |
| 459 | if ctxErr.HasError() { |
| 460 | return |
| 461 | } |
| 462 | // Create new element and deserialize from buffer |
| 463 | elem := reflect.New(typeInfo.Type).Elem() |
| 464 | typeInfo.Serializer.ReadData(ctx, elem) |
| 465 | if ctx.HasError() { |
| 466 | return |
| 467 | } |
| 468 | ctx.RefResolver().SetReadObject(refID, elem) |
| 469 | setMapKey(value, elem, keyType) |
| 470 | } else if hasNull { |
| 471 | // No ref tracking but may have nulls: headFlag + typeId + data (or just NullFlag) |
| 472 | headFlag := buf.ReadInt8(ctxErr) |
| 473 | if headFlag == NullFlag { |
| 474 | // Null element - skip for sets |
| 475 | continue |
| 476 | } |
| 477 | // headFlag should be NotNullValueFlag, read type info |
| 478 | typeInfo := ctx.TypeResolver().ReadTypeInfo(buf, ctxErr) |
| 479 | if ctxErr.HasError() { |
| 480 | return |
| 481 | } |
| 482 | elem := reflect.New(typeInfo.Type).Elem() |
| 483 | typeInfo.Serializer.ReadData(ctx, elem) |
| 484 | if ctx.HasError() { |
| 485 | return |
| 486 | } |
| 487 | setMapKey(value, elem, keyType) |
| 488 | } else { |
| 489 | // No ref tracking and no nulls: typeId + data directly |
| 490 | typeInfo := ctx.TypeResolver().ReadTypeInfo(buf, ctxErr) |
no test coverage detected