MCPcopy Create free account
hub / github.com/apache/fory / ReadBytes

Method ReadBytes

go/fory/buffer.go:1620–1644  ·  view source on GitHub ↗

ReadBytes reads n bytes and sets error on bounds violation

(n int, err *Error)

Source from the content-addressed store, hash-verified

1618
1619// ReadBytes reads n bytes and sets error on bounds violation
1620func (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
1647func (b *ByteBuffer) Skip(length int, err *Error) {

Callers 2

ReadBufferObjectMethod · 0.45
readDecimalPartsFunction · 0.45

Calls 2

fillMethod · 0.95
DeserializationErrorfFunction · 0.85

Tested by

no test coverage detected