1 module hunt.http.server.Http2ServerDecoder;
2 
3 import hunt.http.server.Http2ServerConnection;
4 import hunt.http.HttpConnection;
5 
6 import hunt.collection;
7 import hunt.io.ByteBuffer;
8 import hunt.io.channel;
9 import hunt.net.codec.Decoder;
10 import hunt.net.Connection;
11 import hunt.logging;
12 
13 
14 
15 class Http2ServerDecoder : DecoderChain {    
16 
17     this() {
18         super(null);
19     }
20 
21     override
22     DataHandleStatus decode(ByteBuffer buffer, Connection session) {
23         DataHandleStatus resultStatus = DataHandleStatus.Done;
24 
25         if (!buffer.hasRemaining()) {
26             return resultStatus;
27         }
28 
29         version(HUNT_HTTP_DEBUG) {
30             tracef("buffer: %s", buffer.toString());
31             tracef("the server session %s received the %s bytes", session.getId(), buffer.remaining());
32         }
33 
34         Http2ServerConnection connection = cast(Http2ServerConnection) session.getAttribute(HttpConnection.NAME);
35         connection.getParser().parse(BufferUtils.toHeapBuffer(buffer));
36         //connection.getParser().parse(buffer);
37         BufferUtils.clear(buffer);
38 
39         return resultStatus;
40     }
41 
42     
43 
44     //  public void decode(ByteBuffer buffer, Session session) {
45     //    if (!buffer.hasRemaining()) {
46     //        return;
47     //    }
48     //
49     //    if (log.isDebugEnabled()) {
50     //        log.debug("the server session {} received the {} bytes", session.getSessionId(), buffer.remaining());
51     //    }
52     //
53     //    HTTP2ServerConnection connection = (HTTP2ServerConnection) session.getAttachment();
54     //    connection.getParser().parse(toHeapBuffer(buffer));
55     //}
56 
57 }