Read deserializes a set from the buffer into the provided reflect.Value
(ctx *ReadContext, value reflect.Value)
| 309 | |
| 310 | // Read deserializes a set from the buffer into the provided reflect.Value |
| 311 | func (s setSerializer) ReadData(ctx *ReadContext, value reflect.Value) { |
| 312 | buf := ctx.Buffer() |
| 313 | err := ctx.Err() |
| 314 | type_ := value.Type() |
| 315 | // ReadData collection length from buffer |
| 316 | length := ctx.ReadCollectionLength() |
| 317 | if ctx.HasError() { |
| 318 | return |
| 319 | } |
| 320 | if length == 0 { |
| 321 | // Initialize empty set if length is 0 |
| 322 | value.Set(reflect.MakeMap(type_)) |
| 323 | return |
| 324 | } |
| 325 | |
| 326 | // ReadData collection flags that indicate special characteristics |
| 327 | collectFlag := buf.ReadInt8(err) |
| 328 | if ctx.HasError() { |
| 329 | return |
| 330 | } |
| 331 | var elemTypeInfo *TypeInfo |
| 332 | |
| 333 | // If all elements are same type, get element type info |
| 334 | if (collectFlag & CollectionIsSameType) != 0 { |
| 335 | if (collectFlag & CollectionIsDeclElementType) != 0 { |
| 336 | // Element type is declared in schema, derive from Go type's key type |
| 337 | keyType := type_.Key() |
| 338 | elemSerializer := s.elemSerializer |
| 339 | if elemSerializer == nil { |
| 340 | var err error |
| 341 | elemSerializer, err = ctx.TypeResolver().getSerializerByType(keyType, false) |
| 342 | if err != nil { |
| 343 | ctx.SetError(FromError(err)) |
| 344 | return |
| 345 | } |
| 346 | } |
| 347 | elemTypeInfo = &TypeInfo{Type: keyType, Serializer: elemSerializer} |
| 348 | } else { |
| 349 | // Element type is not declared, read from buffer |
| 350 | elemTypeInfo = ctx.TypeResolver().ReadTypeInfo(buf, err) |
| 351 | } |
| 352 | } |
| 353 | if ctx.HasError() { |
| 354 | return |
| 355 | } |
| 356 | if !buf.CheckReadable(length, err) { |
| 357 | return |
| 358 | } |
| 359 | |
| 360 | // Initialize set if nil |
| 361 | if value.IsNil() { |
| 362 | value.Set(reflect.MakeMapWithSize(type_, length)) |
| 363 | } |
| 364 | // Register reference for tracking (handles circular references) |
| 365 | ctx.RefResolver().Reference(value) |
| 366 | |
| 367 | // Choose appropriate deserialization path based on type consistency |
| 368 | if (collectFlag & CollectionIsSameType) != 0 { |
no test coverage detected