1 module hunt.http.codec.websocket.frame.DataFrame;
2 
3 import hunt.http.codec.websocket.frame.AbstractWebSocketFrame;
4 import hunt.http.WebSocketCommon;
5 import hunt.http.WebSocketFrame;
6 
7 /**
8  * A Data Frame
9  */
10 class DataFrame : AbstractWebSocketFrame {
11     protected this(byte opcode) {
12         super(opcode);
13     }
14 
15     /**
16      * Construct new DataFrame based on headers of provided frame.
17      * <p>
18      * Useful for when working in extensions and a new frame needs to be created.
19      *
20      * @param basedOn the frame this one is based on
21      */
22     this(WebSocketFrame basedOn) {
23         this(basedOn, false);
24     }
25 
26     /**
27      * Construct new DataFrame based on headers of provided frame, overriding for continuations if needed.
28      * <p>
29      * Useful for when working in extensions and a new frame needs to be created.
30      *
31      * @param basedOn      the frame this one is based on
32      * @param continuation true if this is a continuation frame
33      */
34     this(WebSocketFrame basedOn, bool continuation) {
35         super(basedOn.getOpCode());
36         copyHeaders(basedOn);
37         if (continuation) {
38             setOpCode(OpCode.CONTINUATION);
39         }
40     }
41 
42     override
43     void assertValid() {
44         /* no extra validation for data frames (yet) here */
45     }
46 
47     override
48     bool isControlFrame() {
49         return false;
50     }
51 
52     override
53     bool isDataFrame() {
54         return true;
55     }
56 
57     /**
58      * Set the data frame to continuation mode
59      */
60     void setIsContinuation() {
61         setOpCode(OpCode.CONTINUATION);
62     }
63 }