shikeyin
2024-01-11 65da8373531677b1c37a98f53eaa30c892f35e5a
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package com.iplatform.tcp.support;
 
import com.walker.tcp.littleD.Constants;
import com.walker.tcp.littleD.LittleDProtocolResolver;
 
/**
 * 平台TCP通信协议解析器实现。
 * <p>沿用小D智能终端协议规范,#为结束标志,前缀可修改(2位),协议编号4位</p>
 * @author 时克英
 * @date 2023-04-17
 */
public class PlatformSharpProtocolResolver extends LittleDProtocolResolver {
 
    public PlatformSharpProtocolResolver(){
        this.setDelimiter(Constants.DATA_END_FLAG);
        this.setProtocolFeature(Constants.BODY_ID);
        this.setName("平台通信解析器");
        this.setOrder(1);
    }
 
//    @Override
//    protected String onResolve(String data, int size) throws ProtocolException {
//        if(size < 6){
//            throw new ProtocolException(ERR_PROTOCOL_SIZE);
//        }
//
//        if(!source.startsWith(this.getProtocolFeature().toString())){
//            throw new ProtocolException(ERR_PROTOCOL_FEATURE);
//        }
//        return source.substring(2, 6);
//    }
//    @Override
//    protected Response<?> doCreateOneResponse() {
//        // 返回心跳响应
//        return new HeartBeatResponse();
//    }
//    @Override
//    public String getAuthenticateInfo(Request<?> request) throws AuthenticateException {
//        if(request instanceof LoginRequest){
//            String clientId = request.getName();
//            if(StringUtils.isEmpty(clientId)){
//                throw new AuthenticateException("请求信息中不存在设备ID号,无法认证");
//            }
//
//            if(!isPermitNotRegisterConnect() && !this.isRegistered(clientId)){
//                throw new AuthenticateException("设备未在列表中注册,无法认证。clientId = " + clientId);
//            }
//            return clientId;
//
//        } else {
//            throw new AuthenticateException("connection通道认证失败,请求不是登录");
//        }
//    }
 
}