ReadBufferObject reads a buffer object
()
| 667 | |
| 668 | // ReadBufferObject reads a buffer object |
| 669 | func (c *ReadContext) ReadBufferObject() *ByteBuffer { |
| 670 | err := c.Err() |
| 671 | isInBand := c.buffer.ReadBool(err) |
| 672 | if isInBand { |
| 673 | size := c.ReadBinaryLength() |
| 674 | if c.HasError() { |
| 675 | return nil |
| 676 | } |
| 677 | if c.buffer.reader != nil { |
| 678 | bytes := c.buffer.ReadBytes(size, err) |
| 679 | if c.HasError() { |
| 680 | return nil |
| 681 | } |
| 682 | return NewByteBuffer(bytes) |
| 683 | } |
| 684 | if !c.buffer.CheckReadable(size, err) { |
| 685 | return nil |
| 686 | } |
| 687 | buf := c.buffer.Slice(c.buffer.readerIndex, size) |
| 688 | c.buffer.readerIndex += size |
| 689 | return buf |
| 690 | } |
| 691 | // Out-of-band: get the next buffer from the out-of-band buffers list |
| 692 | if c.outOfBandBuffers == nil || c.outOfBandIndex >= len(c.outOfBandBuffers) { |
| 693 | c.SetError(DeserializationErrorf("out-of-band buffer expected but not available at index %d", c.outOfBandIndex)) |
| 694 | return nil |
| 695 | } |
| 696 | buf := c.outOfBandBuffers[c.outOfBandIndex] |
| 697 | c.outOfBandIndex++ |
| 698 | return buf |
| 699 | } |
| 700 | |
| 701 | // incDepth increments the nesting depth and checks for overflow |
| 702 | func (c *ReadContext) incDepth() { |