Skip skips n bytes and sets error on bounds violation
(length int, err *Error)
| 1645 | |
| 1646 | // Skip skips n bytes and sets error on bounds violation |
| 1647 | func (b *ByteBuffer) Skip(length int, err *Error) { |
| 1648 | if length < 0 { |
| 1649 | if err != nil { |
| 1650 | *err = DeserializationErrorf("negative skip length: %d", length) |
| 1651 | } |
| 1652 | return |
| 1653 | } |
| 1654 | if length > len(b.data)-b.readerIndex { |
| 1655 | if b.reader == nil { |
| 1656 | if err != nil { |
| 1657 | *err = BufferOutOfBoundError(b.readerIndex, length, len(b.data)) |
| 1658 | } |
| 1659 | return |
| 1660 | } |
| 1661 | available := len(b.data) - b.readerIndex |
| 1662 | b.readerIndex = len(b.data) |
| 1663 | if !b.discardFromReader(length-available, err) { |
| 1664 | return |
| 1665 | } |
| 1666 | return |
| 1667 | } |
| 1668 | b.readerIndex += length |
| 1669 | } |
| 1670 | |
| 1671 | // CheckReadable ensures that at least n bytes are available to read. |
| 1672 | // In stream mode, it will attempt to fill the buffer if necessary. |