package com.peterhi;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import com.peterhi.Person.Gender;
import com.peterhi.sample.Sample;
public class TestWrite {
public static void main(String[] args) throws Exception {
Sample sample = Functions.newLocalInstance(Sample.class);
sample.setName("Sample 1");
Person jason = Functions.newLocalInstance(Person.class);
jason.setName("Jason");
Gender jasonGender = Functions.newLocalInstance(Gender.class);
jasonGender.setName("Male");
jasonGender.setType(Gender.TYPE_MASCULINE);
jason.setGender(jasonGender);
jason.setAge(40);
jason.setSample(sample);
Person nancy = Functions.newLocalInstance(Person.class);
nancy.setName("Nancy");
Gender nancyGender = Functions.newLocalInstance(Gender.class);
nancyGender.setName("Female");
nancyGender.setType(Gender.TYPE_FEMININE);
nancy.setGender(nancyGender);
nancy.setSample(sample);
nancy.setAge(34);
jason.setSpouse(nancy);
nancy.setSpouse(jason);
Pet kitty = new Pet();
kitty.setName("kitty");
kitty.setAge(2);
kitty.setKind("cat");
Pet bark = new Pet();
bark.setName("bark");
bark.setAge(5);
bark.setKind("dog");
Pet mist = new Pet();
mist.setName("mist");
mist.setAge(1);
mist.setKind("spider");
jason.pets().add(kitty);
jason.pets().add(bark);
jason.pets().add(mist);
nancy.pets().add(kitty);
nancy.pets().add(bark);
nancy.pets().add(mist);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ProtocolOutputStream pos = new ProtocolOutputStream(baos);
int written = pos.writeProtocol(jason);
pos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
ProtocolInputStream pis = new ProtocolInputStream(bais);
int[] length = new int[1];
Protocol protocol = pis.readProtocol(length);
System.out.println(baos.size() + ", " + written + " LENGTH = " + length[0]);
System.out.println(bais.available());
System.out.println(protocol);
Person per = (Person )protocol;
System.out.println(per.getName());
System.out.println(per.getSpouse().getName());
}
}