private byte[] encBodyList(String senderId,
            MsgType msgType, boolean sepByLF, TcpEventInfo eventInfo, ProcessResult procResult) {
        try {
            int totalCnt = 0;
            ByteArrayOutputStream bodyOut = new ByteArrayOutputStream();
            if (msgType == MsgType.MSG_ACK_SERVICE) {
                for (byte[] entry : eventInfo.getBodyList()) {
                    if (totalCnt++ > 0) {
                        bodyOut.write(AttributeConstants.LINE_FEED_SEP.getBytes(StandardCharsets.UTF_8));
                    }
                    bodyOut.write(entry);
                }
            } else if (msgType == MsgType.MSG_MULTI_BODY) {
                for (byte[] entry : eventInfo.getBodyList()) {
                    ByteBuffer byteBuffer = ByteBuffer.allocate(4);
                    byteBuffer.putInt(entry.length);
                    bodyOut.write(byteBuffer.array());
                    bodyOut.write(entry);
                }
            } else {
                if (sepByLF) {
                    ByteArrayOutputStream data = new ByteArrayOutputStream();
                    for (byte[] entry : eventInfo.getBodyList()) {
                        if (totalCnt++ > 0) {
                            data.write(AttributeConstants.LINE_FEED_SEP.getBytes(StandardCharsets.UTF_8));
                        }
                        data.write(entry);
                    }
                    ByteBuffer dataBuffer = ByteBuffer.allocate(4);
                    dataBuffer.putInt(data.toByteArray().length);
                    bodyOut.write(dataBuffer.array());
                    bodyOut.write(data.toByteArray());
                } else {
                    for (byte[] entry : eventInfo.getBodyList()) {
                        ByteBuffer dataBuffer = ByteBuffer.allocate(4);
                        dataBuffer.putInt(entry.length);
                        bodyOut.write(dataBuffer.array());
                        bodyOut.write(entry);
                    }
                }
            }
            return bodyOut.toByteArray();
        } catch (Throwable ex) {
            procResult.setFailResult(ErrorCode.ENCODE_BODY_EXCEPTION, ex.getMessage());
            if (tcpExceptCnt.shouldPrint()) {
                logger.warn("Sender({}) encode 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