ReadBytes reads n bytes and sets error on bounds violation
(n int, err *Error)
| 1618 | |
| 1619 | // ReadBytes reads n bytes and sets error on bounds violation |
| 1620 | func (b *ByteBuffer) ReadBytes(n int, err *Error) []byte { |
| 1621 | if n < 0 { |
| 1622 | if err != nil { |
| 1623 | *err = DeserializationErrorf("negative byte count: %d", n) |
| 1624 | } |
| 1625 | return nil |
| 1626 | } |
| 1627 | if n > len(b.data)-b.readerIndex { |
| 1628 | if !b.fill(n, err) { |
| 1629 | return nil |
| 1630 | } |
| 1631 | } |
| 1632 | |
| 1633 | if b.reader != nil { |
| 1634 | // In stream mode, compaction might overwrite these bytes, so we must copy |
| 1635 | result := make([]byte, n) |
| 1636 | copy(result, b.data[b.readerIndex:b.readerIndex+n]) |
| 1637 | b.readerIndex += n |
| 1638 | return result |
| 1639 | } |
| 1640 | |
| 1641 | p := b.data[b.readerIndex : b.readerIndex+n] |
| 1642 | b.readerIndex += n |
| 1643 | return p |
| 1644 | } |
| 1645 | |
| 1646 | // Skip skips n bytes and sets error on bounds violation |
| 1647 | func (b *ByteBuffer) Skip(length int, err *Error) { |
no test coverage detected