discardReadBytes method

int discardReadBytes()

Discards all already read bytes and shifts all contents to the left, so that readerIndex is 0 again. The writerIndex gets decreased by the amount of bytes freed.


Returns the amount of bytes freed.

Implementation

int discardReadBytes() {
  var readOffset = readerIndex;
  var readable = readableBytes;
  for (var i = 0; i < readable; i++) {
    updateByte(i, getByte(readOffset + i));
  }
  readerIndex = 0;
  writerIndex = readable;
  return readOffset;
}