1 module hunt.http.codec.http.frame.DataFrame;
2 
3 import hunt.io.ByteBuffer;
4 
5 import hunt.http.codec.http.frame.Frame;
6 import hunt.http.codec.http.frame.FrameType;
7 
8 import std.format;
9 
10 class DataFrame :Frame {
11 	private int streamId;
12 	private ByteBuffer data;
13 	private bool endStream;
14 	private int _padding;
15 
16 	this(int streamId, ByteBuffer data, bool endStream) {
17 		this(streamId, data, endStream, 0);
18 	}
19 
20 	this(int streamId, ByteBuffer data, bool endStream, int padding) {
21 		super(FrameType.DATA);
22 		this.streamId = streamId;
23 		this.data = data;
24 		this.endStream = endStream;
25 		this._padding = padding;
26 	}
27 
28 	int getStreamId() {
29 		return streamId;
30 	}
31 
32 	ByteBuffer getData() {
33 		return data;
34 	}
35 
36 	bool isEndStream() {
37 		return endStream;
38 	}
39 
40 	/**
41 	 * @return the number of data bytes remaining.
42 	 */
43 	int remaining() {
44 		return data.remaining();
45 	}
46 
47 	/**
48 	 * @return the number of bytes used for padding that count towards flow
49 	 *         control.
50 	 */
51 	int padding() {
52 		return _padding;
53 	}
54 
55 	override
56 	string toString() {
57 		return format("%s#%d{length:%d,end=%b}", super.toString(), streamId, data.remaining(), endStream);
58 	}
59 }