code: private ByteBuf tryCompress(ByteBuf buf) {
          final int uncompressedLength = buf.readableBytes();
          final byte[] compressed = new byte[Snappy.maxCompressedLength(uncompressedLength)];
          final int compressedLength;
  
          if (buf.hasArray()) {
              // Save a memory copy by reading directly from the backing array.
              compressedLength = Snappy.compress(
                      buf.array(), buf.arrayOffset() + buf.readerIndex(), uncompressedLength, compressed, 0);
          } else {
              final byte[] data = new byte[buf.readableBytes()];
              buf.getBytes(buf.readerIndex(), data);
              compressedLength = Snappy.compress(data, 0, data.length, compressed, 0);
          }
  
          final double ratio = (double) compressedLength / uncompressedLength;
          if (ratio > minCompressionRatio) {
              // Compression doesn't make enough of a difference.
              return null;
          }
  
          // Save a memory copy by deferring trimming until we know the result will be used.
          final byte[] trimmedCompressed = Arrays.copyOf(compressed, compressedLength);
          return Unpooled.wrappedBuffer(trimmedCompressed);
      }
docs: Returns a new buffer with the Snappy-compressed contents of the given buffer starting from the reader index,
  or {@code null} if the compression ratio is not satisfactory.