Mercurial > hg > Members > sugi > MessagePack-java
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cb825acd883a |
---|---|
1 package org.msgpack.simple; | |
2 | |
3 import java.nio.ByteBuffer; | |
4 import java.io.IOException; | |
5 | |
6 import org.msgpack.MessagePack; | |
7 import org.msgpack.type.Value; | |
8 | |
9 import static org.junit.Assert.assertEquals; | |
10 import static org.junit.Assert.assertArrayEquals; | |
11 import org.junit.Test; | |
12 | |
13 | |
14 public class TestSimplePackUnpack { | |
15 @SuppressWarnings("unused") | |
16 @Test | |
17 public void testSimplePackUnpack() throws IOException { | |
18 MessagePack msgpack = new MessagePack(); | |
19 | |
20 // serialize | |
21 byte[] raw = msgpack.write(new int[] {1,2,3}); | |
22 | |
23 // deserialize to static type | |
24 int[] a = msgpack.read(raw, new int[3]); | |
25 assertArrayEquals(new int[] {1,2,3}, a); | |
26 | |
27 // deserialize to dynamic type (see TestSimpleDynamicTyping.java) | |
28 Value v = msgpack.read(raw); | |
29 | |
30 // ByteBuffer is also supported | |
31 int[] ab = msgpack.read(ByteBuffer.wrap(raw), new int[3]); | |
32 assertArrayEquals(new int[] {1,2,3}, ab); | |
33 } | |
34 } | |
35 |