# HG changeset patch # User one # Date 1370786863 -32400 # Node ID 6fbdb09fb0e6823059c201d5a7cd72083526a73b # Parent a7cd9a10033bc60a804591e5fc1ff3599b15ea6c add PracticeEnum diff -r a7cd9a10033b -r 6fbdb09fb0e6 src/ie/oshiro/messagepack/enumpractice/PracticeEnum.java --- a/src/ie/oshiro/messagepack/enumpractice/PracticeEnum.java Sun Jun 09 13:13:02 2013 +0900 +++ b/src/ie/oshiro/messagepack/enumpractice/PracticeEnum.java Sun Jun 09 23:07:43 2013 +0900 @@ -1,9 +1,11 @@ package ie.oshiro.messagepack.enumpractice; import java.io.IOException; +import java.nio.ByteBuffer; import org.msgpack.MessagePack; -import org.msgpack.annotation.Message; +import org.msgpack.template.OrdinalEnumTemplate; +import org.msgpack.template.Template; import org.msgpack.type.Value; public class PracticeEnum { @@ -11,15 +13,30 @@ MessagePack msgpack = new MessagePack(); OperationA opA = new OperationA(); OperationB opB = new OperationB(); - Value vA = msgpack.unconvert(opA); Value vB = msgpack.unconvert(opB); OperationA convertedOpA = msgpack.convert(vA, OperationA.class); OperationB convertedOpB = msgpack.convert(vB, OperationB.class); - System.out.println("opA :"+convertedOpA.getCommand()); System.out.println("opB :"+convertedOpB.getCommand()); + + Command c = Command.COMMAND_A; + Template tmpl = new OrdinalEnumTemplate(c.getClass()); + msgpack.register(c.getClass(), tmpl); + Value cValue = msgpack.unconvert(c); + Command convertedC = msgpack.convert(cValue, Command.class); + System.out.println("convertedC = "+ convertedC); + + ByteBuffer bb = ByteBuffer.allocate(6); + bb.putChar('a'); + bb.putChar('b'); + bb.putChar('c'); + Value bbValue = msgpack.unconvert(bb.array()); + byte[] convertedBB = msgpack.convert(bbValue, byte[].class); + String str = new String(convertedBB); + System.out.println("ByteBuffer : "+str); + } }