use of org.eclipse.jetty.websocket.common.frames.BinaryFrame in project jetty.project by eclipse.
the class TestABCase1_2 method testGenerate128ByteBinaryCase1_2_5.
@Test
public void testGenerate128ByteBinaryCase1_2_5() {
int length = 128;
ByteBuffer bb = ByteBuffer.allocate(length);
for (int i = 0; i < length; ++i) {
bb.put("*".getBytes());
}
bb.flip();
WebSocketFrame binaryFrame = new BinaryFrame().setPayload(bb);
ByteBuffer actual = UnitGenerator.generate(binaryFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
expected.put(new byte[] { (byte) 0x82 });
// no masking
byte b = 0x00;
b |= 0x7E;
expected.put(b);
expected.put((byte) (length >> 8));
expected.put((byte) (length & 0xFF));
for (int i = 0; i < length; ++i) {
expected.put("*".getBytes());
}
BufferUtil.flipToFlush(expected, 0);
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
use of org.eclipse.jetty.websocket.common.frames.BinaryFrame in project jetty.project by eclipse.
the class TestABCase1_2 method testGenerate65535ByteBinaryCase1_2_6.
@Test
public void testGenerate65535ByteBinaryCase1_2_6() {
int length = 65535;
ByteBuffer bb = ByteBuffer.allocate(length);
for (int i = 0; i < length; ++i) {
bb.put("*".getBytes());
}
bb.flip();
WebSocketFrame binaryFrame = new BinaryFrame().setPayload(bb);
ByteBuffer actual = UnitGenerator.generate(binaryFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 5);
expected.put(new byte[] { (byte) 0x82 });
// no masking
byte b = 0x00;
b |= 0x7E;
expected.put(b);
expected.put(new byte[] { (byte) 0xff, (byte) 0xff });
for (int i = 0; i < length; ++i) {
expected.put("*".getBytes());
}
BufferUtil.flipToFlush(expected, 0);
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
use of org.eclipse.jetty.websocket.common.frames.BinaryFrame in project jetty.project by eclipse.
the class TestABCase1_2 method testGenerate65536ByteBinaryCase1_2_7.
@Test
public void testGenerate65536ByteBinaryCase1_2_7() {
int length = 65536;
ByteBuffer bb = ByteBuffer.allocate(length);
for (int i = 0; i < length; ++i) {
bb.put("*".getBytes());
}
bb.flip();
WebSocketFrame binaryFrame = new BinaryFrame().setPayload(bb);
ByteBuffer actual = UnitGenerator.generate(binaryFrame);
ByteBuffer expected = ByteBuffer.allocate(length + 11);
expected.put(new byte[] { (byte) 0x82 });
// no masking
byte b = 0x00;
b |= 0x7F;
expected.put(b);
expected.put(new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00 });
for (int i = 0; i < length; ++i) {
expected.put("*".getBytes());
}
BufferUtil.flipToFlush(expected, 0);
ByteBufferAssert.assertEquals("buffers do not match", expected, actual);
}
Aggregations