package com.firefly.codec.spdy.frames;

import java.nio.ByteBuffer;

public class DataFrame implements Serialization{
	public static final int HEADER_LENGTH = 8;

    private final int streamId;
    private final byte flags;
    private final int length;
    private final ByteBuffer data;

	public DataFrame(int streamId, byte flags, ByteBuffer data) {
		this.streamId = streamId;
		this.flags = flags;
		this.length = data.remaining();
		this.data = data;
	}

	public int getStreamId() {
		return streamId;
	}

	public byte getFlags() {
		return flags;
	}

	public int getLength() {
		return length;
	}
	
	public ByteBuffer getData() {
		return data;
	}

	public boolean isClose() {
		return (flags & Constants.FLAG_CLOSE) == Constants.FLAG_CLOSE;
	}

	@Override
	public String toString() {
		return "DataFrame [streamId=" + streamId + ", flags=" + flags
				+ ", length=" + length + "]";
	}

	@Override
	public ByteBuffer toByteBuffer() {
		ByteBuffer buffer = ByteBuffer.allocate(HEADER_LENGTH + length);
		buffer.putInt(streamId & 0x7F_FF_FF_FF);
		int flagsAndLength = flags;
        flagsAndLength <<= 24;
        flagsAndLength += length;
        buffer.putInt(flagsAndLength);
        buffer.put(data);
		return buffer;
	}
    
}

@@ -251,43 +251,8 @@
 gth;
-%0A    private final ByteBuffer data;
 %0A%0A%09p
@@ -297,23 +297,18 @@
 gs, 
-ByteBuffer data
+int length
 ) %7B%0A
@@ -377,44 +377,14 @@
 h = 
-data.remaining();%0A%09%09this.data = data
+length
 ;%0A%09%7D
@@ -531,59 +531,8 @@
 ;%0A%09%7D
-%0A%09%0A%09public ByteBuffer getData() %7B%0A%09%09return data;%0A%09%7D
 %0A%0A%09p
@@ -1062,34 +1062,8 @@
 h);%0A
-        buffer.put(data);%0A
 %09%09re

modify SPDY data frame