4
|
1 package ie.oshiro.messagepack.enumpractice;
|
|
2
|
|
3 import java.io.IOException;
|
5
|
4 import java.nio.ByteBuffer;
|
4
|
5
|
|
6 import org.msgpack.MessagePack;
|
5
|
7 import org.msgpack.template.OrdinalEnumTemplate;
|
|
8 import org.msgpack.template.Template;
|
4
|
9 import org.msgpack.type.Value;
|
|
10
|
|
11 public class PracticeEnum {
|
|
12 public static void main(String[] args) throws IOException {
|
|
13 MessagePack msgpack = new MessagePack();
|
|
14 OperationA opA = new OperationA();
|
|
15 OperationB opB = new OperationB();
|
|
16 Value vA = msgpack.unconvert(opA);
|
|
17 Value vB = msgpack.unconvert(opB);
|
|
18
|
|
19 OperationA convertedOpA = msgpack.convert(vA, OperationA.class);
|
|
20 OperationB convertedOpB = msgpack.convert(vB, OperationB.class);
|
|
21 System.out.println("opA :"+convertedOpA.getCommand());
|
|
22 System.out.println("opB :"+convertedOpB.getCommand());
|
5
|
23
|
|
24 Command c = Command.COMMAND_A;
|
|
25 Template tmpl = new OrdinalEnumTemplate(c.getClass());
|
|
26 msgpack.register(c.getClass(), tmpl);
|
|
27 Value cValue = msgpack.unconvert(c);
|
|
28 Command convertedC = msgpack.convert(cValue, Command.class);
|
|
29 System.out.println("convertedC = "+ convertedC);
|
|
30
|
|
31 ByteBuffer bb = ByteBuffer.allocate(6);
|
|
32 bb.putChar('a');
|
|
33 bb.putChar('b');
|
|
34 bb.putChar('c');
|
|
35 Value bbValue = msgpack.unconvert(bb.array());
|
|
36 byte[] convertedBB = msgpack.convert(bbValue, byte[].class);
|
|
37 String str = new String(convertedBB);
|
|
38 System.out.println("ByteBuffer : "+str);
|
|
39
|
4
|
40 }
|
|
41
|
|
42 }
|