Skip to content

Commit 4c31415

Browse files
committed
add msgpack.org.md for msgpack.org
Signed-off-by: Tsuyoshi Ozawa <ozawa.tsuyoshi@gmail.com>
1 parent 5778071 commit 4c31415

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

msgpack.org.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# MessagePack for Java
2+
3+
## How to install
4+
5+
You can install msgpack via maven:
6+
7+
<dependencies>
8+
...
9+
<dependency>
10+
<groupId>org.msgpack</groupId>
11+
<artifactId>msgpack</artifactId>
12+
<version>${msgpack.version}</version>
13+
</dependency>
14+
...
15+
</dependencies>
16+
17+
## Simple Serialization/Deserialization/Duck Typing using Value
18+
19+
// Create serialize objects.
20+
List<String> src = new ArrayList<String>();
21+
src.add("msgpack");
22+
src.add("kumofs");
23+
src.add("viver");
24+
25+
MessagePack msgpack = new MessagePack();
26+
// Serialize
27+
byte[] raw = msgpack.write(src);
28+
29+
// Deserialize directly using a template
30+
List<String> dst1 = msgpack.read(raw, Templates.tList(Templates.TString));
31+
System.out.println(dst1.get(0));
32+
System.out.println(dst1.get(1));
33+
System.out.println(dst1.get(2));
34+
35+
// Or, Deserialze to Value then convert type.
36+
Value dynamic = msgpack.read(raw);
37+
List<String> dst2 = new Converter(dynamic)
38+
.read(Templates.tList(Templates.TString));
39+
System.out.println(dst2.get(0));
40+
System.out.println(dst2.get(1));
41+
System.out.println(dst2.get(2));
42+
43+
44+

0 commit comments

Comments
 (0)