Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 05065c6b7807771e265692e3c8d111af025b0213 (plain) (blame)
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
112
113
114
115
//
//  ========================================================================
//  Copyright (c) 1995-2013 Mort Bay Consulting Pty. Ltd.
//  ------------------------------------------------------------------------
//  All rights reserved. This program and the accompanying materials
//  are made available under the terms of the Eclipse Public License v1.0
//  and Apache License v2.0 which accompanies this distribution.
//
//      The Eclipse Public License is available at
//      http://www.eclipse.org/legal/epl-v10.html
//
//      The Apache License v2.0 is available at
//      http://www.opensource.org/licenses/apache2.0.php
//
//  You may elect to redistribute this code under either of these licenses.
//  ========================================================================
//

package org.eclipse.jetty.websocket.mux.op;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.websocket.mux.MuxControlBlock;
import org.eclipse.jetty.websocket.mux.MuxOp;

public class MuxAddChannelRequest implements MuxControlBlock
{
    public static final byte IDENTITY_ENCODING = (byte)0x00;
    public static final byte DELTA_ENCODING = (byte)0x01;

    private long channelId = -1;
    private byte encoding;
    private ByteBuffer handshake;
    private byte rsv;

    public long getChannelId()
    {
        return channelId;
    }

    public byte getEncoding()
    {
        return encoding;
    }

    public ByteBuffer getHandshake()
    {
        return handshake;
    }

    public long getHandshakeSize()
    {
        if (handshake == null)
        {
            return 0;
        }
        return handshake.remaining();
    }

    @Override
    public int getOpCode()
    {
        return MuxOp.ADD_CHANNEL_REQUEST;
    }

    public byte getRsv()
    {
        return rsv;
    }

    public boolean isDeltaEncoded()
    {
        return (encoding == DELTA_ENCODING);
    }

    public boolean isIdentityEncoded()
    {
        return (encoding == IDENTITY_ENCODING);
    }

    public void setChannelId(long channelId)
    {
        this.channelId = channelId;
    }

    public void setEncoding(byte enc)
    {
        this.encoding = enc;
    }

    public void setHandshake(ByteBuffer handshake)
    {
        if (handshake == null)
        {
            this.handshake = null;
        }
        else
        {
            this.handshake = handshake.slice();
        }
    }

    public void setHandshake(String rawstring)
    {
        setHandshake(BufferUtil.toBuffer(rawstring, StandardCharsets.UTF_8));
    }

    public void setRsv(byte rsv)
    {
        this.rsv = rsv;
    }
}

Back to the top