code: public static int indexOf(ByteBuf needle, ByteBuf haystack) {
          // TODO: maybe use Boyer Moore for efficiency.
          int attempts = haystack.readableBytes() - needle.readableBytes() + 1;
          for (int i = 0; i < attempts; i++) {
              if (equals(needle, needle.readerIndex(),
                         haystack, haystack.readerIndex() + i,
                         needle.readableBytes())) {
                  return haystack.readerIndex() + i;
              }
          }
          return -1;
      }
docs: Returns the reader index of needle in haystack, or -1 if needle is not in haystack.