1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.eclipse.jetty.websocket.common.extensions.mux.op;
20
21 import java.nio.ByteBuffer;
22 import java.nio.charset.StandardCharsets;
23
24 import org.eclipse.jetty.util.BufferUtil;
25 import org.eclipse.jetty.util.StringUtil;
26 import org.eclipse.jetty.websocket.common.extensions.mux.MuxControlBlock;
27 import org.eclipse.jetty.websocket.common.extensions.mux.MuxOp;
28
29 public class MuxAddChannelResponse implements MuxControlBlock
30 {
31 public static final byte IDENTITY_ENCODING = (byte)0x00;
32 public static final byte DELTA_ENCODING = (byte)0x01;
33
34 private long channelId;
35 private byte encoding;
36 private byte rsv;
37 private boolean failed = false;
38 private ByteBuffer handshake;
39
40 public long getChannelId()
41 {
42 return channelId;
43 }
44
45 public byte getEncoding()
46 {
47 return encoding;
48 }
49
50 public ByteBuffer getHandshake()
51 {
52 return handshake;
53 }
54
55 public long getHandshakeSize()
56 {
57 if (handshake == null)
58 {
59 return 0;
60 }
61 return handshake.remaining();
62 }
63
64 @Override
65 public int getOpCode()
66 {
67 return MuxOp.ADD_CHANNEL_RESPONSE;
68 }
69
70 public byte getRsv()
71 {
72 return rsv;
73 }
74
75 public boolean isDeltaEncoded()
76 {
77 return (encoding == DELTA_ENCODING);
78 }
79
80 public boolean isFailed()
81 {
82 return failed;
83 }
84
85 public boolean isIdentityEncoded()
86 {
87 return (encoding == IDENTITY_ENCODING);
88 }
89
90 public void setChannelId(long channelId)
91 {
92 this.channelId = channelId;
93 }
94
95 public void setEncoding(byte enc)
96 {
97 this.encoding = enc;
98 }
99
100 public void setFailed(boolean failed)
101 {
102 this.failed = failed;
103 }
104
105 public void setHandshake(ByteBuffer handshake)
106 {
107 if (handshake == null)
108 {
109 this.handshake = null;
110 }
111 else
112 {
113 this.handshake = handshake.slice();
114 }
115 }
116
117 public void setHandshake(String responseHandshake)
118 {
119 setHandshake(BufferUtil.toBuffer(responseHandshake, StandardCharsets.UTF_8));
120 }
121
122 public void setRsv(byte rsv)
123 {
124 this.rsv = rsv;
125 }
126 }