Created
July 13, 2010 02:19
-
-
Save frsyuki/473364 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.io.*; | |
import org.msgpack.*; | |
class Test { | |
public static void main(String[] args) throws Exception { | |
// シリアライズしたいオブジェクト | |
List<String> list = new ArrayList<String>(); | |
list.add("msgpack"); | |
list.add("kumofs"); | |
// シリアライズ | |
ByteArrayOutputStream out = new ByteArrayOutputStream(); | |
Packer pk = new Packer(out); | |
pk.pack(list); | |
// 入力ストリーム | |
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray()); | |
// デシリアライザオブジェクトを作成:"(array string)"の型変換スキーマで | |
Unpacker pac = new Unpacker(in).useSchema(Schema.parse("(array string)")); | |
// 1つのオブジェクトだけデシリアライズする場合 | |
UnpackResult result = pac.next(); | |
List<String> data1 = (List<String>)result.getData(); | |
System.out.println("deserialized: "+data1); | |
String str = data1.get(1); | |
// 複数のオブジェクトを次々にデシリアライズする場合 | |
for(Object obj : pac) { | |
List<String> data = obj; | |
System.out.println("deserialized: "+data); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment