code: private int indexOf(ByteBuf haystack, byte[] needle) {
  		for (int i = haystack.readerIndex(); i < haystack.writerIndex(); i++) {
  			int haystackIndex = i;
  			int needleIndex;
  			for (needleIndex = 0; needleIndex < needle.length; needleIndex++) {
  				if (haystack.getByte(haystackIndex) != needle[needleIndex]) {
  					break;
  				} else {
  					haystackIndex++;
  					if (haystackIndex == haystack.writerIndex() &&
  							needleIndex != needle.length - 1) {
  						return -1;
  					}
  				}
  			}
  
  			if (needleIndex == needle.length) {
  				// Found the needle from the haystack!
  				return i - haystack.readerIndex();
  			}
  		}
  		return -1;
  	}
docs: Returns the number of bytes between the readerIndex of the haystack and
  the first needle found in the haystack.  -1 is returned if no needle is
  found in the haystack.
  <p/>
  Copied from {@link io.netty.handler.codec.DelimiterBasedFrameDecoder}.