List of usage examples for io.netty.buffer ByteBufUtil getBytes
public static byte[] getBytes(ByteBuf buf)
From source file:io.datty.msgpack.test.CompositeByteBufTest.java
License:Apache License
@Test public void testCompositeWrite() { ByteBuf first = Unpooled.buffer();//from w w w . ja v a 2 s . c o m first.writeByte('a'); CompositeByteBuf result = first.alloc().compositeBuffer(); result.addComponent(true, first); result.writeByte('b'); byte[] actual = ByteBufUtil.getBytes(result); Assert.assertEquals(2, actual.length); Assert.assertEquals('a', actual[0]); Assert.assertEquals('b', actual[1]); }
From source file:io.datty.msgpack.test.MessageReaderTypedTest.java
License:Apache License
protected void assertPrimitivesExample(byte[] example) { Map<String, Object> map = readWithSchema(example, PR_SCHEMA); Assert.assertEquals(map.get("boolean"), true); Assert.assertEquals(map.get("Boolean"), true); Assert.assertEquals(map.get("byte"), (byte) 1); Assert.assertEquals(map.get("Byte"), (byte) 1); Assert.assertEquals(map.get("short"), (short) 1); Assert.assertEquals(map.get("Short"), (short) 1); Assert.assertEquals(map.get("int"), (int) 1); Assert.assertEquals(map.get("Integer"), (int) 1); Assert.assertEquals(map.get("long"), (long) 1); Assert.assertEquals(map.get("Long"), (long) 1); Assert.assertEquals(map.get("float"), (float) 1); Assert.assertEquals(map.get("Float"), (float) 1); Assert.assertEquals(map.get("double"), (double) 1); Assert.assertEquals(map.get("Double"), (double) 1); Assert.assertEquals(map.get("String"), "1"); ByteBuf bb = (ByteBuf) map.get("ByteBuf"); byte[] bytes = ByteBufUtil.getBytes(bb); Assert.assertTrue(Arrays.equals(bytes, new byte[] { 1 })); }
From source file:io.datty.msgpack.test.MessageWriterInnerTest.java
License:Apache License
@Test public void testWriteInnerMap() { MessageWriter writer = MapMessageWriter.INSTANCE; ByteBuf sink = Unpooled.buffer();//from ww w .j ava 2 s .c o m int headerIndex = writer.skipHeader(10, sink); writer.writeKey("id", sink); writer.writeValue(777, sink); writer.writeKey("name", sink); writeMapNames(sink); writer.writeHeader(2, 10, headerIndex, sink); byte[] bytes = ByteBufUtil.getBytes(sink); assertInnerMapExample(bytes); }
From source file:io.datty.msgpack.test.MessageWriterInnerTest.java
License:Apache License
@Test public void testWriteInnerArray() { MessageWriter writer = MapMessageWriter.INSTANCE; ByteBuf sink = Unpooled.buffer();/*www.j a va2 s . c om*/ int headerIndex = writer.skipHeader(10, sink); writer.writeKey("id", sink); writer.writeValue(777, sink); writer.writeKey("names", sink); writeArrayNames(sink); writer.writeHeader(2, 10, headerIndex, sink); byte[] bytes = ByteBufUtil.getBytes(sink); System.out.println(Arrays.toString(bytes)); assertInnerArrayExample(bytes); }
From source file:io.datty.msgpack.test.MessageWriterTest.java
License:Apache License
@Test public void testIntMap() { MessageWriter writer = MapMessageWriter.INSTANCE; ByteBuf sink = Unpooled.buffer();/*from ww w . ja va 2s . c o m*/ writer.writeHeader(FIELDS_COUNT, sink); writeIntMapFields(writer, sink); byte[] bytes = ByteBufUtil.getBytes(sink); assertIntMapExample(bytes); }
From source file:io.datty.msgpack.test.MessageWriterTest.java
License:Apache License
@Test public void testIntMapSkip() { MessageWriter writer = MapMessageWriter.INSTANCE; ByteBuf sink = Unpooled.buffer();//from w w w . j av a 2 s . co m int headerIndex = writer.skipHeader(10, sink); writeIntMapFields(writer, sink); writer.writeHeader(FIELDS_COUNT, 10, headerIndex, sink); byte[] bytes = ByteBufUtil.getBytes(sink); assertIntMapExample(bytes); }
From source file:io.datty.msgpack.test.MessageWriterTest.java
License:Apache License
@Test public void testStringMap() { MessageWriter writer = MapMessageWriter.INSTANCE; ByteBuf sink = Unpooled.buffer();/*from www. j a v a 2 s. c om*/ writer.writeHeader(FIELDS_COUNT, sink); writeStringMapFields(writer, sink); byte[] bytes = ByteBufUtil.getBytes(sink); assertStringMapExample(bytes); }
From source file:io.datty.msgpack.test.MessageWriterTest.java
License:Apache License
@Test public void testStringMapSkip() { MessageWriter writer = MapMessageWriter.INSTANCE; ByteBuf sink = Unpooled.buffer();/* w w w. j ava 2 s . c o m*/ int headerIndex = writer.skipHeader(10, sink); writeStringMapFields(writer, sink); writer.writeHeader(FIELDS_COUNT, 10, headerIndex, sink); byte[] bytes = ByteBufUtil.getBytes(sink); assertStringMapExample(bytes); }
From source file:io.datty.msgpack.test.MessageWriterTest.java
License:Apache License
@Test public void testArray() { MessageWriter writer = ArrayMessageWriter.INSTANCE; ByteBuf sink = Unpooled.buffer();/*from w ww. ja v a 2 s . com*/ writer.writeHeader(FIELDS_COUNT, sink); writeArrayFields(writer, sink); byte[] bytes = ByteBufUtil.getBytes(sink); assertArrayExample(bytes); }
From source file:io.datty.msgpack.test.MessageWriterTest.java
License:Apache License
@Test public void testArraySkip() { MessageWriter writer = ArrayMessageWriter.INSTANCE; ByteBuf sink = Unpooled.buffer();/*w w w . ja v a2 s .c o m*/ int headerIndex = writer.skipHeader(10, sink); writeArrayFields(writer, sink); writer.writeHeader(FIELDS_COUNT, 10, headerIndex, sink); byte[] bytes = ByteBufUtil.getBytes(sink); assertArrayExample(bytes); }