view src/ie/oshiro/messagepack/practice/MSGFJListTest.java @ 7:98144dbff410 default tip

Added WriteHardDisk.java : Msgpack practice
author one
date Sat, 12 Oct 2013 19:42:55 +0900
parents 79c8067c34ec
children
line wrap: on
line source

package ie.oshiro.messagepack.practice;

import java.io.IOException;

import org.msgpack.MessagePack;
import org.msgpack.template.ListTemplate;
import org.msgpack.template.ValueTemplate;
import org.msgpack.type.Value;

import fj.data.List;

public class MSGFJListTest {

	public static void main(String[] args) throws IOException { 
		MessagePack msgpack = new MessagePack();
		List<Integer> writeList = List.nil();
		writeList = writeList.cons(1);
		writeList = writeList.cons(2);
		writeList = writeList.cons(3);
		byte[] bytes;
		bytes = msgpack.write(writeList);
		// Cannot find template for class fj.data.List class
		msgpack.register(List.class, new ListTemplate(ValueTemplate.getInstance()));
		for(Value v: (List<Value>) msgpack.read(bytes, List.class)) {
			System.out.println(v.asIntegerValue());
		}
		System.out.println(writeList);
/*
		// Cannot find template for class fj.data.List class
		Value v = msgpack.unconvert(writeList);
		List<Integer> readList = (List<Integer>)msgpack.convert(v, List.class);
		for(Integer i: readList) {
			System.out.println(i);
		}
*/

		
		
	}

}