package com.peterhi.working;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import com.peterhi.working.Decoder;
import com.peterhi.working.Encoder;
import com.peterhi.working.Person.B.C;
public class CodecTest {
public static void main(String[] args) throws Exception {
// test1();
test2();
}
private static void test1() throws Exception {
Person jason = new Person();
jason.setName("Jason");
jason.setAge(36);
jason.setAliases(new String[] { "HAHA" });
jason.addAlias("Jesson");
jason.addAlias("JSON");
Person marilyn = new Person();
marilyn.setName("Marilyn");
marilyn.setAge(34);
marilyn.setAliases(new String[] { "Mary" });
marilyn.addAlias("Marry");
marilyn.addAlias("Merry");
jason.setSpouse(marilyn);
marilyn.setSpouse(jason);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Encoder enc = new Encoder(baos);
enc.encode(jason);
enc.close();
System.out.println("BAOS size = " + baos.size());
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
Decoder dec = new Decoder(bais);
Person j = dec.decode();
dec.close();
System.out.println(bais.available());
System.out.println(j.getSpouse().getName());
}
private static void test2() throws Exception {
C c = new C();
c.setAny(new String[][] {
null,
new String[0],
new String[] { "A" },
new String[] { "B", "C" },
});
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Encoder enc = new Encoder(baos);
enc.encode(c);
enc.close();
System.out.println("Size = " + baos.size());
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
Decoder dec = new Decoder(bais);
C c2 = dec.decode();
System.out.println(Arrays.deepToString((Object[] )c2.getAny()));
dec.close();
System.out.println("Available = " + bais.available());
}
}