Mercurial > hg > Members > nobuyasu > PracticeJava
changeset 2:79c8067c34ec
add MSInterFaceTest.java
author | one |
---|---|
date | Fri, 07 Jun 2013 20:26:28 +0900 |
parents | 95fc62831771 |
children | 5b77974d641b |
files | src/ie/oshiro/messagepack/practice/MSGFJListTest.java src/ie/oshiro/messagepack/practice/MSInterFaceTest.java src/ie/oshiro/messagepack/practice/MyClass.java src/ie/oshiro/messagepack/practice/MyInterface.java |
diffstat | 4 files changed, 76 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ie/oshiro/messagepack/practice/MSGFJListTest.java Tue Jun 04 19:55:40 2013 +0900 +++ b/src/ie/oshiro/messagepack/practice/MSGFJListTest.java Fri Jun 07 20:26:28 2013 +0900 @@ -3,7 +3,6 @@ import java.io.IOException; import org.msgpack.MessagePack; -import org.msgpack.annotation.Message; import org.msgpack.template.ListTemplate; import org.msgpack.template.ValueTemplate; import org.msgpack.type.Value; @@ -33,6 +32,8 @@ System.out.println(i); } */ + + }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ie/oshiro/messagepack/practice/MSInterFaceTest.java Fri Jun 07 20:26:28 2013 +0900 @@ -0,0 +1,40 @@ +package ie.oshiro.messagepack.practice; + +import java.io.IOException; +import java.util.LinkedList; + +import org.msgpack.MessagePack; +import org.msgpack.template.ListTemplate; +import org.msgpack.template.ValueTemplate; +import org.msgpack.type.Value; + +import java.util.List; + +public class MSInterFaceTest { + + @SuppressWarnings("unchecked") + public static void main(String[] args) throws IOException { + MessagePack msgpack = new MessagePack(); + MyClass m = new MyClass(5); + Value v = msgpack.unconvert(m); + MyClass mm = (MyClass)msgpack.convert(v, MyClass.class); + System.out.println("num = " + mm.getNum()); + + + LinkedList<MyClass> list = new LinkedList<MyClass>(); + list.add(new MyClass()); + list.add(new MyClass()); + list.add(new MyClass()); +// m.setIter(list); + + MessagePack msgpack2 = new MessagePack(); + byte[] bytes; + bytes = msgpack2.write(list); + msgpack2.register(List.class, new ListTemplate(ValueTemplate.getInstance())); + for(Value v2: (List<Value>) msgpack2.read(bytes, List.class)) { + MyClass m2 = msgpack2.convert(v2, MyClass.class); + System.out.println("m2 = "+m2.getNum()); + } + + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/ie/oshiro/messagepack/practice/MyClass.java Fri Jun 07 20:26:28 2013 +0900 @@ -0,0 +1,28 @@ +package ie.oshiro.messagepack.practice; + +import org.msgpack.annotation.Message; + +@Message +public class MyClass implements MyInterface { + + private Iterable<MyClass> iter; + + int num; + MyClass() { + iter = null; + num = 0; + } + MyClass(int i) { + iter = null; + num = i; + } + public int getNum() { return num; } + public void setNum(int i) { num = i; } + + public void setIter(Iterable<MyClass> _iter) { + iter = _iter; + } + public Iterable<MyClass> getIter() { + return iter; + } +}