1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.handler.codec;
17
18 import static io.netty.util.internal.ObjectUtil.checkNotNull;
19
20
21
22
23
24
25 public final class ProtocolDetectionResult<T> {
26
27 @SuppressWarnings({ "rawtypes", "unchecked" })
28 private static final ProtocolDetectionResult NEEDS_MORE_DATA =
29 new ProtocolDetectionResult(ProtocolDetectionState.NEEDS_MORE_DATA, null);
30 @SuppressWarnings({ "rawtypes", "unchecked" })
31 private static final ProtocolDetectionResult INVALID =
32 new ProtocolDetectionResult(ProtocolDetectionState.INVALID, null);
33
34 private final ProtocolDetectionState state;
35 private final T result;
36
37
38
39
40 @SuppressWarnings("unchecked")
41 public static <T> ProtocolDetectionResult<T> needsMoreData() {
42 return NEEDS_MORE_DATA;
43 }
44
45
46
47
48 @SuppressWarnings("unchecked")
49 public static <T> ProtocolDetectionResult<T> invalid() {
50 return INVALID;
51 }
52
53
54
55
56 @SuppressWarnings("unchecked")
57 public static <T> ProtocolDetectionResult<T> detected(T protocol) {
58 return new ProtocolDetectionResult<T>(ProtocolDetectionState.DETECTED, checkNotNull(protocol, "protocol"));
59 }
60
61 private ProtocolDetectionResult(ProtocolDetectionState state, T result) {
62 this.state = state;
63 this.result = result;
64 }
65
66
67
68
69
70 public ProtocolDetectionState state() {
71 return state;
72 }
73
74
75
76
77 public T detectedProtocol() {
78 return result;
79 }
80 }