liurunyu
2024-09-07 9ad6b0179be4d351105f1507779d4f41a3a41953
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.dy.testClient.tcpClient;
 
import com.dy.common.util.ByteUtil;
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;
 
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[] preByte = new byte[remain];
            in.get(preByte) ;
            in.position(0) ;
            log.info("收到中心下行数据:" + ByteUtil.bytes2Hex(preByte, true));
        }
        return true;
    }
 
 
}