| New file | 
|  |  |  | 
|---|
|  |  |  | package com.dy.simRtu202404.tcpClient; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.dy.common.util.ByteUtil; | 
|---|
|  |  |  | import com.dy.simRtu202404.tcpClient.downData.DownData; | 
|---|
|  |  |  | import org.apache.logging.log4j.LogManager; | 
|---|
|  |  |  | import org.apache.logging.log4j.Logger; | 
|---|
|  |  |  | import org.apache.mina.core.buffer.IoBuffer; | 
|---|
|  |  |  | import org.apache.mina.core.session.IoSession; | 
|---|
|  |  |  | import org.apache.mina.filter.codec.CumulativeProtocolDecoder; | 
|---|
|  |  |  | import org.apache.mina.filter.codec.ProtocolDecoderOutput; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.io.IOException; | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Author: liurunyu | 
|---|
|  |  |  | * @Date: 2025/02/26 11:10 | 
|---|
|  |  |  | * @Description | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public class LocalDecoder extends CumulativeProtocolDecoder { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final Logger log = LogManager.getLogger(LocalDecoder.class) ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private static final String DECODER_STATE_KEY = LocalDecoder.class.getName() + ".STATE"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public static final int MAX_SIZE = 2147483647 ; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 对网络传输来的数据进行解码 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws IOException, Exception{ | 
|---|
|  |  |  | int remain = in.remaining() ; | 
|---|
|  |  |  | if(remain > 0){ | 
|---|
|  |  |  | byte[] bs = new byte[remain]; | 
|---|
|  |  |  | in.get(bs) ; | 
|---|
|  |  |  | in.position(0) ; | 
|---|
|  |  |  | log.info("收到中间件下行数据:" + ByteUtil.bytes2Hex(bs, true)); | 
|---|
|  |  |  | new DownData().parseData(bs); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|