code: public static int compare(ByteBuf bufferA, ByteBuf bufferB) {
          final int aLen = bufferA.readableBytes();
          final int bLen = bufferB.readableBytes();
          final int minLength = Math.min(aLen, bLen);
          final int uintCount = minLength >>> 2;
          final int byteCount = minLength & 3;
          int aIndex = bufferA.readerIndex();
          int bIndex = bufferB.readerIndex();
  
          if (uintCount > 0) {
              boolean bufferAIsBigEndian = bufferA.order() == ByteOrder.BIG_ENDIAN;
              final long res;
              int uintCountIncrement = uintCount << 2;
  
              if (bufferA.order() == bufferB.order()) {
                  res = bufferAIsBigEndian ? compareUintBigEndian(bufferA, bufferB, aIndex, bIndex, uintCountIncrement) :
                          compareUintLittleEndian(bufferA, bufferB, aIndex, bIndex, uintCountIncrement);
              } else {
                  res = bufferAIsBigEndian ? compareUintBigEndianA(bufferA, bufferB, aIndex, bIndex, uintCountIncrement) :
                          compareUintBigEndianB(bufferA, bufferB, aIndex, bIndex, uintCountIncrement);
              }
              if (res != 0) {
                  // Ensure we not overflow when cast
                  return (int) Math.min(Integer.MAX_VALUE, Math.max(Integer.MIN_VALUE, res));
              }
              aIndex += uintCountIncrement;
              bIndex += uintCountIncrement;
          }
  
          for (int aEnd = aIndex + byteCount; aIndex < aEnd; ++aIndex, ++bIndex) {
              int comp = bufferA.getUnsignedByte(aIndex) - bufferB.getUnsignedByte(bIndex);
              if (comp != 0) {
                  return comp;
              }
          }
  
          return aLen - bLen;
      }
docs: Compares the two specified buffers as described in {@link ByteBuf#compareTo(ByteBuf)}.
  This method is useful when implementing a new buffer type.