prot.writeFieldBegin(new TField());
prot.writeString("hello world!");
prot.writeFieldEnd();
prot.writeFieldBegin(new TField());
prot.writeMapBegin(new TMap());
prot.writeString("key1");
prot.writeString("val1");
prot.writeString("key2");
prot.writeString("val2");
prot.writeString("key3");
prot.writeString("val3");
prot.writeMapEnd();
prot.writeFieldEnd();
prot.writeFieldBegin(new TField());
prot.writeListBegin(new TList());
prot.writeString("elem1");
prot.writeString("elem2");
prot.writeListEnd();
prot.writeFieldEnd();
prot.writeFieldBegin(new TField());
prot.writeString("bye!");
prot.writeFieldEnd();
prot.writeStructEnd();
trans.flush();
byte[] b = new byte[3 * 1024];
int len = trans.read(b, 0, b.length);
String test = new String(b, 0, len);
String testRef =
"100348.55234.22hello world!key1val1key2val2key3val3elem1elem2bye!";
assertTrue(test.equals(testRef));
trans = new TMemoryBuffer(1023);
trans.write(b, 0, len);
//
// read back!
//
prot = new TCTLSeparatedProtocol(trans, 10);
prot.initialize(new Configuration(), new Properties());
// 100 is the start
prot.readStructBegin();
prot.readFieldBegin();
assertTrue(prot.readI32() == 100);
prot.readFieldEnd();
// let's see if doubles work ok
prot.readFieldBegin();
TList l = prot.readListBegin();
assertTrue(l.size == 2);
assertTrue(prot.readDouble() == 348.55);
assertTrue(prot.readDouble() == 234.22);
prot.readListEnd();
prot.readFieldEnd();
// nice message
prot.readFieldBegin();
assertTrue(prot.readString().equals("hello world!"));
prot.readFieldEnd();
// 3 element map
prot.readFieldBegin();
TMap m = prot.readMapBegin();
assertTrue(m.size == 3);
assertTrue(prot.readString().equals("key1"));
assertTrue(prot.readString().equals("val1"));
assertTrue(prot.readString().equals("key2"));
assertTrue(prot.readString().equals("val2"));