List of usage examples for io.netty.buffer Unpooled wrappedBuffer
public static ByteBuf wrappedBuffer(ByteBuffer... buffers)
From source file:io.datty.msgpack.test.MessageReaderInnerTest.java
License:Apache License
protected void assertInnerMapExample(byte[] example) { ByteBuf source = Unpooled.wrappedBuffer(example); Object message = MessageIO.readValue(source, false); Assert.assertTrue(message instanceof Map); @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) message; Assert.assertEquals(map.get("id"), Long.valueOf(777)); @SuppressWarnings("unchecked") Map<String, Object> innerMap = (Map<String, Object>) map.get("name"); Assert.assertNotNull(innerMap);//from ww w . j ava 2s. co m Assert.assertEquals(innerMap.get("first"), "John"); Assert.assertEquals(innerMap.get("last"), "Dow"); }
From source file:io.datty.msgpack.test.MessageReaderInnerTest.java
License:Apache License
protected void assertInnerArrayExample(byte[] example) { ByteBuf source = Unpooled.wrappedBuffer(example); Object message = MessageIO.readValue(source, false); Assert.assertTrue(message instanceof Map); @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) message; Assert.assertEquals(map.get("id"), Long.valueOf(777)); @SuppressWarnings("unchecked") List<Object> innerArray = (List<Object>) map.get("names"); Assert.assertNotNull(innerArray);/*from ww w . j a va2s . com*/ Assert.assertEquals(innerArray.get(0), "John"); Assert.assertEquals(innerArray.get(1), "Dow"); }
From source file:io.datty.msgpack.test.MessageReaderTest.java
License:Apache License
protected void assertIntMapExample(byte[] example) { ByteBuf source = Unpooled.wrappedBuffer(example); Object message = MessageIO.readValue(source, false); Assert.assertTrue(message instanceof Map); @SuppressWarnings("unchecked") Map<Integer, Object> map = (Map<Integer, Object>) message; Assert.assertEquals(map.get(1), "123"); Assert.assertEquals(map.get(2), Long.valueOf(-9)); Assert.assertEquals(map.get(3), "Alex"); }
From source file:io.datty.msgpack.test.MessageReaderTest.java
License:Apache License
protected void assertStringMapExample(byte[] example) { ByteBuf source = Unpooled.wrappedBuffer(example); Object message = MessageIO.readValue(source, false); Assert.assertTrue(message instanceof Map); @SuppressWarnings("unchecked") Map<Object, Object> map = (Map<Object, Object>) message; Assert.assertEquals(map.get("acc"), "123"); Assert.assertEquals(map.get("logins"), Long.valueOf(-9)); Assert.assertEquals(map.get("name"), "Alex"); }
From source file:io.datty.msgpack.test.MessageReaderTest.java
License:Apache License
protected void assertArrayExample(byte[] example) { ByteBuf source = Unpooled.wrappedBuffer(example); Object message = MessageIO.readValue(source, false); Assert.assertTrue(message instanceof List); @SuppressWarnings("unchecked") List<Object> array = (List<Object>) message; Assert.assertEquals(array.get(0), "123"); Assert.assertEquals(array.get(1), Long.valueOf(-9)); Assert.assertEquals(array.get(2), "Alex"); }
From source file:io.datty.msgpack.test.MessageReaderTypedTest.java
License:Apache License
protected Map<String, Object> readWithSchema(byte[] example, Map<String, Class<?>> schema) { ByteBuf source = Unpooled.wrappedBuffer(example); Object value = ValueMessageReader.INSTANCE.readValue(source, false); Assert.assertTrue(value instanceof MapMessageReader); MessageReader reader = (MessageReader) value; Map<String, Object> map = new HashMap<>(); for (int i = 0; i != reader.size(); i++) { Object key = reader.readKey(source); Class<?> type = schema.get(key); Assert.assertNotNull(type);/*from w w w . j av a 2s .c o m*/ Object field = reader.readValue(typeOf(type), source, false); Assert.assertNotNull((String) key, field); map.put((String) key, field); } return map; }
From source file:io.datty.msgpack.test.MessageWriterTypedTest.java
License:Apache License
@Test public void testPrimitives() { ByteBuf sink = Unpooled.buffer();/*ww w. j ava 2 s.c o m*/ MessageWriter writer = MapMessageWriter.INSTANCE; int headerIndex = writer.skipHeader(255, sink); int fields = 0; writer.writeKey("boolean", sink); writer.writeValue(typeOf(boolean.class), true, sink, true); fields++; writer.writeKey("Boolean", sink); writer.writeValue(typeOf(Boolean.class), true, sink, true); fields++; writer.writeKey("byte", sink); writer.writeValue(typeOf(byte.class), (byte) 1, sink, true); fields++; writer.writeKey("Byte", sink); writer.writeValue(typeOf(Byte.class), (byte) 1, sink, true); fields++; writer.writeKey("short", sink); writer.writeValue(typeOf(short.class), (short) 1, sink, true); fields++; writer.writeKey("Short", sink); writer.writeValue(typeOf(Short.class), (short) 1, sink, true); fields++; writer.writeKey("int", sink); writer.writeValue(typeOf(int.class), (int) 1, sink, true); fields++; writer.writeKey("Integer", sink); writer.writeValue(typeOf(Integer.class), (int) 1, sink, true); fields++; writer.writeKey("long", sink); writer.writeValue(typeOf(long.class), (long) 1, sink, true); fields++; writer.writeKey("Long", sink); writer.writeValue(typeOf(Long.class), (long) 1, sink, true); fields++; writer.writeKey("float", sink); writer.writeValue(typeOf(float.class), (float) 1, sink, true); fields++; writer.writeKey("Float", sink); writer.writeValue(typeOf(Float.class), (float) 1, sink, true); fields++; writer.writeKey("double", sink); writer.writeValue(typeOf(double.class), (double) 1, sink, true); fields++; writer.writeKey("Double", sink); writer.writeValue(typeOf(Double.class), (double) 1, sink, true); fields++; writer.writeKey("String", sink); writer.writeValue(typeOf(String.class), "1", sink, true); fields++; writer.writeKey("ByteBuf", sink); writer.writeValue(typeOf(ByteBuf.class), Unpooled.wrappedBuffer(new byte[] { 1 }), sink, true); fields++; writer.writeHeader(fields, 255, headerIndex, sink); byte[] bytes = ByteBufUtil.getBytes(sink); assertPrimitivesExample(bytes); }
From source file:io.datty.spring.converter.AllArraysConverterTest.java
License:Apache License
@Test public void testOnes() throws Exception { ByteBuf one = Unpooled.wrappedBuffer(new byte[] { 1 }); AllArraysEntity entity = new AllArraysEntity(); entity.setBooleanVal(new boolean[] { true }); entity.setBooleanWal(new Boolean[] { true }); entity.setByteVal(new byte[] { 1 }); entity.setByteWal(new Byte[] { 1 }); entity.setShortVal(new short[] { 1 }); entity.setShortWal(new Short[] { 1 }); entity.setIntVal(new int[] { 1 }); entity.setIntWal(new Integer[] { 1 }); entity.setLongVal(new long[] { 1 }); entity.setLongWal(new Long[] { 1L }); entity.setFloatVal(new float[] { 1.0f }); entity.setFloatWal(new Float[] { 1.0f }); entity.setDoubleVal(new double[] { 1.0d }); entity.setDoubleWal(new Double[] { 1.0d }); entity.setStringVal(new String[] { "1" }); entity.setBbVal(new ByteBuf[] { one }); testNotEmpty(entity);/*from w w w. j ava 2 s . c o m*/ }
From source file:io.datty.spring.converter.AllListsConverterTest.java
License:Apache License
@Test public void testOnes() throws Exception { ByteBuf one = Unpooled.wrappedBuffer(new byte[] { 1 }); AllListsEntity entity = new AllListsEntity(); entity.setBooleanVal(Arrays.asList(true)); entity.setByteVal(Arrays.asList((byte) 1)); entity.setShortVal(Arrays.asList((short) 1)); entity.setIntVal(Arrays.asList(1)); entity.setLongVal(Arrays.asList(1L)); entity.setFloatVal(Arrays.asList(1.0f)); entity.setDoubleVal(Arrays.asList(1.0d)); entity.setStringVal(Arrays.asList("1")); entity.setBbVal(Arrays.asList(one)); testNotEmpty(entity);/*from w w w . j ava 2s. c om*/ }
From source file:io.datty.spring.converter.AllMapsConverterTest.java
License:Apache License
@Test public void testOnes() throws Exception { ByteBuf one = Unpooled.wrappedBuffer(new byte[] { 1 }); AllMapsEntity entity = new AllMapsEntity(); entity.setBooleanVal(mapOf(true));//from ww w . ja v a2 s . c o m entity.setByteVal(mapOf((byte) 1)); entity.setShortVal(mapOf((short) 1)); entity.setIntVal(mapOf(1)); entity.setLongVal(mapOf(1L)); entity.setFloatVal(mapOf(1.0f)); entity.setDoubleVal(mapOf(1.0d)); entity.setStringVal(mapOf("1")); entity.setBbVal(mapOf(one)); testNotEmpty(entity); }