(ctx *ReadContext, value reflect.Value, expectedLength int)
| 263 | } |
| 264 | |
| 265 | func (s sliceDynSerializer) readData(ctx *ReadContext, value reflect.Value, expectedLength int) { |
| 266 | buf := ctx.Buffer() |
| 267 | ctxErr := ctx.Err() |
| 268 | length := ctx.ReadCollectionLength() |
| 269 | sliceType := value.Type() |
| 270 | if ctx.HasError() { |
| 271 | return |
| 272 | } |
| 273 | if expectedLength >= 0 && length != expectedLength { |
| 274 | ctx.SetError(DeserializationErrorf("array length %d does not match serialized length %d", expectedLength, length)) |
| 275 | return |
| 276 | } |
| 277 | if length == 0 { |
| 278 | value.Set(reflect.MakeSlice(sliceType, 0, 0)) |
| 279 | return |
| 280 | } |
| 281 | |
| 282 | collectFlag := buf.ReadInt8(ctxErr) |
| 283 | if ctx.HasError() { |
| 284 | return |
| 285 | } |
| 286 | |
| 287 | var elemTypeInfo *TypeInfo |
| 288 | var elemType reflect.Type |
| 289 | var elemSerializer Serializer |
| 290 | if (collectFlag & CollectionIsSameType) != 0 { |
| 291 | if (collectFlag & CollectionIsDeclElementType) == 0 { |
| 292 | elemTypeInfo = ctx.TypeResolver().ReadTypeInfo(buf, ctxErr) |
| 293 | } |
| 294 | if elemTypeInfo != nil && elemTypeInfo.Serializer != nil { |
| 295 | elemType = elemTypeInfo.Type |
| 296 | elemSerializer = elemTypeInfo.Serializer |
| 297 | } else { |
| 298 | // When CollectionIsDeclElementType is set, get serializer from the declared element type |
| 299 | elemType = sliceType.Elem() |
| 300 | elemSerializer, _ = ctx.TypeResolver().getSerializerByType(elemType, false) |
| 301 | } |
| 302 | if ctx.HasError() { |
| 303 | return |
| 304 | } |
| 305 | if !buf.CheckReadable(length, ctxErr) { |
| 306 | return |
| 307 | } |
| 308 | value.Set(reflect.MakeSlice(sliceType, length, length)) |
| 309 | ctx.RefResolver().Reference(value) |
| 310 | s.readSameType(ctx, buf, value, elemType, elemSerializer, collectFlag, length) |
| 311 | return |
| 312 | } |
| 313 | if !buf.CheckReadable(length, ctxErr) { |
| 314 | return |
| 315 | } |
| 316 | value.Set(reflect.MakeSlice(sliceType, length, length)) |
| 317 | ctx.RefResolver().Reference(value) |
| 318 | s.readDifferentTypes(ctx, buf, value, collectFlag, length) |
| 319 | } |
| 320 | |
| 321 | func (s sliceDynSerializer) ReadWithTypeInfo(ctx *ReadContext, refMode RefMode, typeInfo *TypeInfo, value reflect.Value) { |
| 322 | // typeInfo is already read, don't read it again |
no test coverage detected