ReadBinary reads n bytes and sets error on bounds violation
(length int, err *Error)
| 428 | |
| 429 | // ReadBinary reads n bytes and sets error on bounds violation |
| 430 | func (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 | |
| 456 | func (b *ByteBuffer) GetData() []byte { |
| 457 | return b.data |
no test coverage detected