private byte[] compressBodyInfo(String senderId, byte[] body, ProcessResult procResult) {
        try {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            out.write(body);
            int guessLen = Snappy.maxCompressedLength(out.size());
            byte[] tmpData = new byte[guessLen];
            int len = Snappy.compress(out.toByteArray(), 0, out.size(),
                    tmpData, 0);
            body = new byte[len];
            System.arraycopy(tmpData, 0, body, 0, len);
            return body;
        } catch (Throwable ex) {
            procResult.setFailResult(ErrorCode.COMPRESS_BODY_EXCEPTION, ex.getMessage());
            if (tcpExceptCnt.shouldPrint()) {
                logger.warn("Sender({}) compress body exception", senderId, ex);
            }
            return null;
        }
    }
TCP Message Sender class

Used to define the TCP sender common methods
inlong-sdk/dataproxy-sdk/src/main/java/org/apache/inlong/sdk/dataproxy/sender/tcp/InLongTcpMsgSender.java