code: private static int findEndOfLine(final ByteBuf buffer) {
          final int n = buffer.writerIndex();
          for (int i = buffer.readerIndex(); i < n; i++) {
              final byte b = buffer.getByte(i);
              if (b == '\r' && i < n - 1 && buffer.getByte(i + 1) == '\n') {
                  return i;  // \r\n
              }
          }
          return -1;  // Not found.
      }
docs: Returns the index in the buffer of the end of line found.
  Returns -1 if no end of line was found in the buffer.