Mercurial > hg > Members > nobuyasu > PracticeJava
changeset 5:6fbdb09fb0e6
add PracticeEnum
author | one |
---|---|
date | Sun, 09 Jun 2013 23:07:43 +0900 |
parents | a7cd9a10033b |
children | b82cdd44b1c1 |
files | src/ie/oshiro/messagepack/enumpractice/PracticeEnum.java |
diffstat | 1 files changed, 20 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- 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); + } }