(ctx *ReadContext, value reflect.Value)
| 300 | } |
| 301 | |
| 302 | func (s *sliceSerializer) ReadData(ctx *ReadContext, value reflect.Value) { |
| 303 | buf := ctx.Buffer() |
| 304 | ctxErr := ctx.Err() |
| 305 | length := ctx.ReadCollectionLength() |
| 306 | if ctx.HasError() { |
| 307 | return |
| 308 | } |
| 309 | isArrayType := value.Type().Kind() == reflect.Array |
| 310 | |
| 311 | if length == 0 { |
| 312 | if !isArrayType { |
| 313 | value.Set(reflect.MakeSlice(value.Type(), 0, 0)) |
| 314 | } |
| 315 | return |
| 316 | } |
| 317 | |
| 318 | // ReadData collection flags |
| 319 | collectFlag := buf.ReadInt8(ctxErr) |
| 320 | if ctx.HasError() { |
| 321 | return |
| 322 | } |
| 323 | |
| 324 | elemSerializer := s.elemSerializer |
| 325 | |
| 326 | // ReadData element type info if present in buffer. |
| 327 | if (collectFlag & CollectionIsSameType) != 0 { |
| 328 | if (collectFlag & CollectionIsDeclElementType) == 0 { |
| 329 | elemTypeInfo := ctx.TypeResolver().ReadTypeInfo(buf, ctxErr) |
| 330 | if elemTypeInfo != nil && elemTypeInfo.Serializer != nil { |
| 331 | elemSerializer = elemTypeInfo.Serializer |
| 332 | elemType := value.Type().Elem() |
| 333 | if elemTypeInfo.Type != nil { |
| 334 | _, elemSerializer = wrapMapSerializerIfNeeded(elemType, elemTypeInfo.Type, elemSerializer) |
| 335 | } |
| 336 | if elemType.Kind() != reflect.Ptr { |
| 337 | if ptrSer, ok := elemSerializer.(*ptrToValueSerializer); ok { |
| 338 | elemSerializer = ptrSer.valueSerializer |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | if ctx.HasError() { |
| 345 | return |
| 346 | } |
| 347 | |
| 348 | // IMPORTANT: collection readers must obey the TRACKING_REF bit written on the |
| 349 | // wire, not whatever the local field annotation or inferred Go type would |
| 350 | // prefer. Shared xlang tests intentionally deserialize a payload written with |
| 351 | // one ref policy and then reserialize with another. DO NOT REMOVE this |
| 352 | // comment during cleanup or refactors. |
| 353 | trackRefs := (collectFlag & CollectionTrackingRef) != 0 |
| 354 | hasNull := (collectFlag & CollectionHasNull) != 0 |
| 355 | declaredGenericDispatch := (collectFlag&CollectionIsDeclElementType) != 0 && serializerNeedsGenericDispatch(elemSerializer) |
| 356 | |
| 357 | // Handle slice vs array allocation |
| 358 | if isArrayType { |
| 359 | // For arrays, verify the length matches (arrays have fixed size) |
no test coverage detected