2026-06-26 20b96473f2520590a0dca6b775b81e3ea06a77a0
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
package cn.iocoder.yudao.module.iot.gateway.protocol.tcp.codec;
 
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.ReflectUtil;
import cn.iocoder.yudao.module.iot.gateway.protocol.tcp.IotTcpConfig;
 
/**
 * IoT TCP 帧编解码器工厂
 *
 * @author 芋道源码
 */
public class IotTcpFrameCodecFactory {
 
    /**
     * 根据配置创建编解码器
     *
     * @param config 拆包配置
     * @return 编解码器实例,如果配置为空则返回 null
     */
    public static IotTcpFrameCodec create(IotTcpConfig.CodecConfig config) {
        Assert.notNull(config, "CodecConfig 不能为空");
        IotTcpCodecTypeEnum type = IotTcpCodecTypeEnum.of(config.getType());
        Assert.notNull(type, "不支持的 CodecType 类型:" + config.getType());
        return ReflectUtil.newInstance(type.getCodecClass(), config);
    }
 
}