Integrating the new Frame interface

This commit is contained in:
Joakim Erdfelt 2012-07-05 16:14:57 -07:00
parent 46452b9c7a
commit fa023ebc6c
3 changed files with 23 additions and 6 deletions

View File

@ -7,11 +7,11 @@ public interface Frame
{
public byte[] getMask();
public int getOpCode();
public OpCode getOpCode();
public byte[] getPayload();
public byte[] getPayloadData();
public long getPayloadLength();
public int getPayloadLength();
public boolean isFin();

View File

@ -2,6 +2,8 @@ package org.eclipse.jetty.websocket.frames;
import java.nio.ByteBuffer;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.websocket.api.Frame;
import org.eclipse.jetty.websocket.api.OpCode;
/**
@ -28,7 +30,7 @@ import org.eclipse.jetty.websocket.api.OpCode;
* +---------------------------------------------------------------+
* </pre>
*/
public class BaseFrame
public class BaseFrame implements Frame
{
private boolean fin = false;
private boolean rsv1 = false;
@ -55,6 +57,7 @@ public class BaseFrame
this.opcode = opcode;
}
@Override
public byte[] getMask()
{
if (!masked)
@ -64,6 +67,7 @@ public class BaseFrame
return mask;
}
@Override
public final OpCode getOpCode()
{
return opcode;
@ -79,6 +83,13 @@ public class BaseFrame
return payload;
}
@Override
public byte[] getPayloadData()
{
return BufferUtil.toArray(payload);
}
@Override
public int getPayloadLength()
{
return payloadLength;
@ -94,6 +105,7 @@ public class BaseFrame
return false; // always false here
}
@Override
public boolean isFin()
{
return fin;
@ -104,21 +116,25 @@ public class BaseFrame
return fin;
}
@Override
public boolean isMasked()
{
return masked;
}
@Override
public boolean isRsv1()
{
return rsv1;
}
@Override
public boolean isRsv2()
{
return rsv2;
}
@Override
public boolean isRsv3()
{
return rsv3;

View File

@ -85,12 +85,13 @@ public class WebSocketEventDriverTest
driver.onFrame(new BinaryFrame(StringUtil.getUtf8Bytes("Hello Bin")));
driver.onFrame(new CloseFrame(StatusCode.SHUTDOWN));
socket.capture.assertEventCount(5);
socket.capture.assertEventCount(6);
socket.capture.assertEventStartsWith(0,"onConnect(");
socket.capture.assertEventStartsWith(1,"onFrame(Ping");
socket.capture.assertEventStartsWith(2,"onFrame(Text");
socket.capture.assertEventStartsWith(3,"onFrame(Binary");
socket.capture.assertEventStartsWith(4,"onClose(1001,");
socket.capture.assertEventStartsWith(4,"onFrame(Close");
socket.capture.assertEventStartsWith(5,"onClose(1001,");
}
@Test