Mercurial > hg > Members > sugi > MessagePack-java
diff src/test/java/org/msgpack/simple/TestSimplePackUnpack.java @ 0:cb825acd883a
first commit
author | sugi |
---|---|
date | Sat, 18 Oct 2014 15:06:15 +0900 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/test/java/org/msgpack/simple/TestSimplePackUnpack.java Sat Oct 18 15:06:15 2014 +0900 @@ -0,0 +1,35 @@ +package org.msgpack.simple; + +import java.nio.ByteBuffer; +import java.io.IOException; + +import org.msgpack.MessagePack; +import org.msgpack.type.Value; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; +import org.junit.Test; + + +public class TestSimplePackUnpack { + @SuppressWarnings("unused") + @Test + public void testSimplePackUnpack() throws IOException { + MessagePack msgpack = new MessagePack(); + + // serialize + byte[] raw = msgpack.write(new int[] {1,2,3}); + + // deserialize to static type + int[] a = msgpack.read(raw, new int[3]); + assertArrayEquals(new int[] {1,2,3}, a); + + // deserialize to dynamic type (see TestSimpleDynamicTyping.java) + Value v = msgpack.read(raw); + + // ByteBuffer is also supported + int[] ab = msgpack.read(ByteBuffer.wrap(raw), new int[3]); + assertArrayEquals(new int[] {1,2,3}, ab); + } +} +