# HG changeset patch
# User one
# Date 1370794725 -32400
# Node ID 3770d2be3e7326c87564f88ee42a5c77ca5683d3
# Parent 20498c88a70dfdde5916b706a66d265edbacbed6
modified DfaultNodePathContainer
diff -r 20498c88a70d -r 3770d2be3e73 .classpath
--- a/.classpath Sun Jun 09 13:53:16 2013 +0900
+++ b/.classpath Mon Jun 10 01:18:45 2013 +0900
@@ -4,5 +4,6 @@
+
diff -r 20498c88a70d -r 3770d2be3e73 src/jungle/test/datasegment/store/operations/DefaultNodeOperationContainer.java
--- 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;
}
-
}
diff -r 20498c88a70d -r 3770d2be3e73 src/jungle/test/datasegment/store/operations/DefaultNodePathContainer.java
--- a/src/jungle/test/datasegment/store/operations/DefaultNodePathContainer.java Sun Jun 09 13:53:16 2013 +0900
+++ b/src/jungle/test/datasegment/store/operations/DefaultNodePathContainer.java Mon Jun 10 01:18:45 2013 +0900
@@ -1,13 +1,17 @@
package jungle.test.datasegment.store.operations;
import java.io.IOException;
-import java.util.Arrays;
+import java.util.LinkedList;
import java.util.List;
+import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
import org.msgpack.MessagePack;
import org.msgpack.annotation.Message;
+import org.msgpack.template.IntegerTemplate;
+import org.msgpack.template.ListTemplate;
+import org.msgpack.template.ValueTemplate;
import org.msgpack.type.Value;
@Message
@@ -15,24 +19,42 @@
public Value pathValue;
+ public static void main(String[] args) throws IOException {
+ DefaultNodePath p = new DefaultNodePath();
+ p = p.add(1).add(2).add(3);
+ DefaultNodePathContainer pathContainer = new DefaultNodePathContainer();
+ pathContainer.unconvert(p);
+ NodePath convertedPath = pathContainer.convert();
+ for (int i : convertedPath) {
+ System.out.println(i);
+ }
+ }
+
public DefaultNodePathContainer() {
}
public void unconvert(DefaultNodePath path) throws IOException {
MessagePack msgpack = new MessagePack();
- List list = Arrays.asList();
+ List list = new LinkedList();
for(Integer i : path) {
list.add(i);
}
+ /* Remove first Element(-1). */
+ list.remove(0);
+ msgpack.register(List.class, new ListTemplate(IntegerTemplate.getInstance()));
Value v = msgpack.unconvert(list);
pathValue = v;
}
public DefaultNodePath convert() throws IOException {
MessagePack msgpack = new MessagePack();
- return msgpack.convert(pathValue, DefaultNodePath.class);
+ msgpack.register(List.class, new ListTemplate(IntegerTemplate.getInstance()));
+ List convertedList = (List)msgpack.convert(pathValue, List.class);
+ DefaultNodePath path = new DefaultNodePath();
+ for (int i: convertedList) {
+ path = path.add(i);
+ }
+ return path;
}
-
-
}