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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package com.dy.common.mw.channel.tcp;
 
public class PrefixedDataAvailableStatus {
    
    public final static Integer status_rubbish = 0 ;//垃圾数据
    public final static Integer status_break = 1 ;//断包
    public final static Integer status_adjoin = 2 ;//粘包
    public final static Integer status_complete = 3 ;//不断不粘
    
    private Integer status ;
    private Integer dataLen ;
    public String protocolName;
    public Short protocolVersion;
    
    public PrefixedDataAvailableStatus(){
        status = null ;
        dataLen = null ;
    }
    
    /**
     * 垃圾数据
     * @param dataLen 数据长度
     * @return 状态
     */
    @SuppressWarnings("unused")
    public PrefixedDataAvailableStatus rubbish(Integer dataLen){
        this.status = status_rubbish ;
        this.dataLen = dataLen ;
        return this ;
    }
    
    /**
     * 发生断包
     * @return 状态
     */
    @SuppressWarnings("unused")
    public PrefixedDataAvailableStatus breaked(){
        this.status = status_break ;
        this.dataLen = null ;
        return this ;
    }
    
    /**
     * 发生粘包
     * @param dataLen 数据长度
     * @return 状态
     */
    @SuppressWarnings("unused")
    public PrefixedDataAvailableStatus adjoined(Integer dataLen, String protocolName, Short protocolVersion){
        this.status = status_adjoin ;
        this.dataLen = dataLen ;
        this.protocolName = protocolName ;
        this.protocolVersion = protocolVersion ;
        return this ;
    }
    
    /**
     * 不断包不粘包,数据正好收全
     * @param dataLen 数据长度
     * @return 状态
     */
    @SuppressWarnings("unused")
    public PrefixedDataAvailableStatus completed(Integer dataLen, String protocolName, Short protocolVersion){
        this.status = status_complete ;
        this.dataLen = dataLen ;
        this.protocolName = protocolName ;
        this.protocolVersion = protocolVersion ;
        return this ;
    }
    
    /**
     * 是否垃圾数据
     * @return 状态
     */
    public boolean isRubbish(){
        return this.status.intValue() == status_rubbish.intValue();
    }
    /**
     * 是否断包
     * @return 状态
     */
    public boolean isBreaked(){
        return this.status.intValue() == status_break.intValue();
    }
    
    
    /**
     * 是否粘包
     * @return 是否粘包
     */
    public boolean isAdjoined(){
        return this.status.intValue() == status_adjoin.intValue();
    }
    
    /**
     * 是否不断不粘
     * @return 是否不断不粘
     */
    public boolean isCompleted(){
        return this.status.intValue() == status_complete.intValue();
    }
    
    /**
     * 返回数据长度
     * @return 数据长度
     */
    public Integer getDataLen(){
        return this.dataLen ;
    }
    
}