readExt will read the extension type, and return remaining bytes, as well as the data of the extension.
(b []byte)
| 503 | // readExt will read the extension type, and return remaining bytes, |
| 504 | // as well as the data of the extension. |
| 505 | func readExt(b []byte) (typ int8, remain []byte, data []byte, err error) { |
| 506 | l := len(b) |
| 507 | if l < 3 { |
| 508 | return 0, b, nil, ErrShortBytes |
| 509 | } |
| 510 | lead := b[0] |
| 511 | var ( |
| 512 | sz int // size of 'data' |
| 513 | off int // offset of 'data' |
| 514 | ) |
| 515 | switch lead { |
| 516 | case mfixext1: |
| 517 | typ = int8(b[1]) |
| 518 | sz = 1 |
| 519 | off = 2 |
| 520 | case mfixext2: |
| 521 | typ = int8(b[1]) |
| 522 | sz = 2 |
| 523 | off = 2 |
| 524 | case mfixext4: |
| 525 | typ = int8(b[1]) |
| 526 | sz = 4 |
| 527 | off = 2 |
| 528 | case mfixext8: |
| 529 | typ = int8(b[1]) |
| 530 | sz = 8 |
| 531 | off = 2 |
| 532 | case mfixext16: |
| 533 | typ = int8(b[1]) |
| 534 | sz = 16 |
| 535 | off = 2 |
| 536 | case mext8: |
| 537 | sz = int(b[1]) |
| 538 | typ = int8(b[2]) |
| 539 | off = 3 |
| 540 | if sz == 0 { |
| 541 | return typ, b[3:], b[3:3], nil |
| 542 | } |
| 543 | case mext16: |
| 544 | if l < 4 { |
| 545 | return 0, b, nil, ErrShortBytes |
| 546 | } |
| 547 | sz = int(big.Uint16(b[1:])) |
| 548 | typ = int8(b[3]) |
| 549 | off = 4 |
| 550 | case mext32: |
| 551 | if l < 6 { |
| 552 | return 0, b, nil, ErrShortBytes |
| 553 | } |
| 554 | sz = int(big.Uint32(b[1:])) |
| 555 | typ = int8(b[5]) |
| 556 | off = 6 |
| 557 | default: |
| 558 | return 0, b, nil, badPrefix(ExtensionType, lead) |
| 559 | } |
| 560 | // the data of the extension starts |
| 561 | // at 'off' and is 'sz' bytes long |
| 562 | tot := off + sz |
no test coverage detected
searching dependent graphs…