skipMap skips a map value Uses context error state for deferred error checking.
(ctx *ReadContext, fieldDef FieldDef)
| 307 | // skipMap skips a map value |
| 308 | // Uses context error state for deferred error checking. |
| 309 | func skipMap(ctx *ReadContext, fieldDef FieldDef) { |
| 310 | bufErr := ctx.Err() |
| 311 | length := uint32(ctx.ReadCollectionLength()) |
| 312 | if ctx.HasError() || length == 0 { |
| 313 | return |
| 314 | } |
| 315 | |
| 316 | // Extract key/value specs from the declared map type when available. |
| 317 | // When KEY_DECL_TYPE/VALUE_DECL_TYPE flags are set, the type info is NOT written |
| 318 | // to the buffer, so we must use the declared types from the FieldDef |
| 319 | var declaredKeyDef, declaredValueDef FieldDef |
| 320 | if fieldDef.typeSpec != nil && fieldDef.typeSpec.keyType != nil && fieldDef.typeSpec.valueType != nil { |
| 321 | declaredKeyDef = FieldDef{ |
| 322 | typeSpec: fieldDef.typeSpec.keyType, |
| 323 | nullable: true, |
| 324 | } |
| 325 | declaredValueDef = FieldDef{ |
| 326 | typeSpec: fieldDef.typeSpec.valueType, |
| 327 | nullable: true, |
| 328 | } |
| 329 | } else { |
| 330 | // Fallback to unknown types when no declared map key/value specs exist. |
| 331 | declaredKeyDef = FieldDef{ |
| 332 | typeSpec: NewSimpleTypeSpec(UNKNOWN), |
| 333 | nullable: true, |
| 334 | } |
| 335 | declaredValueDef = FieldDef{ |
| 336 | typeSpec: NewSimpleTypeSpec(UNKNOWN), |
| 337 | nullable: true, |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | var lenCounter uint32 |
| 342 | for lenCounter < length { |
| 343 | header := ctx.buffer.ReadByte(bufErr) |
| 344 | if ctx.HasError() { |
| 345 | return |
| 346 | } |
| 347 | |
| 348 | // Both null |
| 349 | if (header&KEY_HAS_NULL) != 0 && (header&VALUE_HAS_NULL) != 0 { |
| 350 | lenCounter++ |
| 351 | continue |
| 352 | } |
| 353 | |
| 354 | // Only key is null |
| 355 | if (header & KEY_HAS_NULL) != 0 { |
| 356 | valueDeclared := (header & VALUE_DECL_TYPE) != 0 |
| 357 | var valueDef FieldDef |
| 358 | var valueTypeInfo *TypeInfo |
| 359 | if !valueDeclared { |
| 360 | typeID := uint32(ctx.buffer.ReadUint8(bufErr)) |
| 361 | if ctx.HasError() { |
| 362 | return |
| 363 | } |
| 364 | valueTypeInfo = readKnownTypeInfoForSkip(ctx, typeID) |
| 365 | if ctx.HasError() { |
| 366 | return |