ReadMapHeader reads the next object as a map header and returns the size of the map and the number of bytes written. It will return a TypeError{} if the next object is not a map.
()
| 429 | // It will return a TypeError{} if the next |
| 430 | // object is not a map. |
| 431 | func (m *Reader) ReadMapHeader() (sz uint32, err error) { |
| 432 | var p []byte |
| 433 | var lead byte |
| 434 | lead, err = m.R.PeekByte() |
| 435 | if err != nil { |
| 436 | return |
| 437 | } |
| 438 | if isfixmap(lead) { |
| 439 | sz = uint32(rfixmap(lead)) |
| 440 | _, err = m.R.Skip(1) |
| 441 | return |
| 442 | } |
| 443 | switch lead { |
| 444 | case mmap16: |
| 445 | p, err = m.R.Next(3) |
| 446 | if err != nil { |
| 447 | return |
| 448 | } |
| 449 | sz = uint32(big.Uint16(p[1:])) |
| 450 | return |
| 451 | case mmap32: |
| 452 | p, err = m.R.Next(5) |
| 453 | if err != nil { |
| 454 | return |
| 455 | } |
| 456 | sz = big.Uint32(p[1:]) |
| 457 | return |
| 458 | default: |
| 459 | err = badPrefix(MapType, lead) |
| 460 | return |
| 461 | } |
| 462 | } |
| 463 | |
| 464 | // ReadMapKey reads either a 'str' or 'bin' field from |
| 465 | // the reader and returns the value as a []byte. It uses |