Mercurial > hg > Database > jungle-network
diff src/jungle/test/datasegment/store/operations/DefaultNodeOperationContainer.java @ 3:3770d2be3e73
modified DfaultNodePathContainer
author | one |
---|---|
date | Mon, 10 Jun 2013 01:18:45 +0900 |
parents | 20498c88a70d |
children |
line wrap: on
line diff
--- a/src/jungle/test/datasegment/store/operations/DefaultNodeOperationContainer.java Sun Jun 09 13:53:16 2013 +0900 +++ b/src/jungle/test/datasegment/store/operations/DefaultNodeOperationContainer.java Mon Jun 10 01:18:45 2013 +0900 @@ -13,7 +13,6 @@ import org.msgpack.MessagePack; import org.msgpack.annotation.Message; import org.msgpack.template.OrdinalEnumTemplate; -import org.msgpack.template.Template; import org.msgpack.type.Value; @Message @@ -24,6 +23,19 @@ public Value value; public Value commandValue; + public static void main(String[] args) throws IOException { + String key = "hoge"; + ByteBuffer b = ByteBuffer.wrap("messagepack value".getBytes()); + PutAttributeOperation op = new PutAttributeOperation(key, b); + DefaultNodeOperationContainer container = new DefaultNodeOperationContainer(); + container.unconvert(op); + NodeOperation convertedOp = container.convert(); + System.out.println("pos : "+convertedOp.getPosition()); + System.out.println("Command : "+convertedOp.getCommand()); + System.out.println("key : "+convertedOp.getKey()); + System.out.println("value : "+new String(convertedOp.getValue().array())); + + } public DefaultNodeOperationContainer() { @@ -36,21 +48,23 @@ value = null; if (op.getValue() != null) { ByteBuffer b = op.getValue(); - Value v = msgpack.unconvert(b); + byte[] bytes = b.array(); + Value v = msgpack.unconvert(bytes); value = v; } Command c = op.getCommand(); - msgpack.register(c.getClass(), new OrdinalEnumTemplate(c.getClass())); + msgpack.register(Command.class, new OrdinalEnumTemplate(Command.class)); Value cValue = msgpack.unconvert(c); commandValue = cValue; } public NodeOperation convert() throws IOException{ MessagePack msgpack = new MessagePack(); + msgpack.register(Command.class, new OrdinalEnumTemplate(Command.class)); Command c = msgpack.convert(commandValue, Command.class); ByteBuffer b = null; if (value != null) { - b = msgpack.convert(value, ByteBuffer.class); + b = ByteBuffer.wrap(msgpack.convert(value, byte[].class)); } if (c == Command.PUT_ATTRIBUTE) { return new PutAttributeOperation(key, b); @@ -64,5 +78,4 @@ return null; } - }