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

Method ReadBinary

go/fory/buffer.go:430–454  ·  view source on GitHub ↗

ReadBinary reads n bytes and sets error on bounds violation

(length int, err *Error)

Source from the content-addressed store, hash-verified

428
429// ReadBinary reads n bytes and sets error on bounds violation
430func (b *ByteBuffer) ReadBinary(length int, err *Error) []byte {
431 if length < 0 {
432 if err != nil {
433 *err = DeserializationErrorf("negative byte count: %d", length)
434 }
435 return nil
436 }
437 if length > len(b.data)-b.readerIndex {
438 if !b.fill(length, err) {
439 return nil
440 }
441 }
442
443 if b.reader != nil {
444 // In stream mode, compaction might overwrite these bytes, so we must copy
445 result := make([]byte, length)
446 copy(result, b.data[b.readerIndex:b.readerIndex+length])
447 b.readerIndex += length
448 return result
449 }
450
451 v := b.data[b.readerIndex : b.readerIndex+length]
452 b.readerIndex += length
453 return v
454}
455
456func (b *ByteBuffer) GetData() []byte {
457 return b.data

Callers 7

testBufferFunction · 0.95
readMetaStringMethod · 0.45
readLatin1Function · 0.45
readUTF16LEFunction · 0.45
readUTF8Function · 0.45
decodeTypeDefFunction · 0.45
readFieldDefFunction · 0.45

Calls 2

fillMethod · 0.95
DeserializationErrorfFunction · 0.85

Tested by

no test coverage detected