use of org.apache.thrift.protocol.TList in project voldemort by voldemort.
the class MockMessage method write.
public void write(TProtocol oprot) throws TException {
validate();
oprot.writeStructBegin(STRUCT_DESC);
if (this.name != null) {
oprot.writeFieldBegin(NAME_FIELD_DESC);
oprot.writeString(this.name);
oprot.writeFieldEnd();
}
if (this.mappings != null) {
oprot.writeFieldBegin(MAPPINGS_FIELD_DESC);
{
oprot.writeMapBegin(new TMap(TType.I64, TType.MAP, this.mappings.size()));
for (Map.Entry<Long, Map<String, Integer>> _iter14 : this.mappings.entrySet()) {
oprot.writeI64(_iter14.getKey());
{
oprot.writeMapBegin(new TMap(TType.STRING, TType.I32, _iter14.getValue().size()));
for (Map.Entry<String, Integer> _iter15 : _iter14.getValue().entrySet()) {
oprot.writeString(_iter15.getKey());
oprot.writeI32(_iter15.getValue());
}
oprot.writeMapEnd();
}
}
oprot.writeMapEnd();
}
oprot.writeFieldEnd();
}
if (this.intList != null) {
oprot.writeFieldBegin(INT_LIST_FIELD_DESC);
{
oprot.writeListBegin(new TList(TType.I16, this.intList.size()));
for (short _iter16 : this.intList) {
oprot.writeI16(_iter16);
}
oprot.writeListEnd();
}
oprot.writeFieldEnd();
}
if (this.strSet != null) {
oprot.writeFieldBegin(STR_SET_FIELD_DESC);
{
oprot.writeSetBegin(new TSet(TType.STRING, this.strSet.size()));
for (String _iter17 : this.strSet) {
oprot.writeString(_iter17);
}
oprot.writeSetEnd();
}
oprot.writeFieldEnd();
}
oprot.writeFieldStop();
oprot.writeStructEnd();
}
use of org.apache.thrift.protocol.TList in project hive by apache.
the class TestTCTLSeparatedProtocol method testQuotedWrites.
public void testQuotedWrites() throws Exception {
TMemoryBuffer trans = new TMemoryBuffer(4096);
TCTLSeparatedProtocol prot = new TCTLSeparatedProtocol(trans, 4096);
Properties schema = new Properties();
schema.setProperty(serdeConstants.QUOTE_CHAR, "\"");
schema.setProperty(serdeConstants.FIELD_DELIM, ",");
prot.initialize(new Configuration(), schema);
String testStr = "\"hello, world!\"";
prot.writeStructBegin(new TStruct());
prot.writeFieldBegin(new TField());
prot.writeString(testStr);
prot.writeFieldEnd();
prot.writeFieldBegin(new TField());
prot.writeListBegin(new TList());
prot.writeString("elem1");
prot.writeString("elem2");
prot.writeListEnd();
prot.writeFieldEnd();
prot.writeStructEnd();
prot.writeString("\n");
trans.flush();
byte[] b = new byte[4096];
int len = trans.read(b, 0, b.length);
trans = new TMemoryBuffer(4096);
trans.write(b, 0, len);
prot = new TCTLSeparatedProtocol(trans, 1024);
prot.initialize(new Configuration(), schema);
prot.readStructBegin();
prot.readFieldBegin();
final String firstRead = prot.readString();
prot.readFieldEnd();
testStr = testStr.replace("\"", "");
assertEquals(testStr, firstRead);
// the 2 element list
prot.readFieldBegin();
TList l = prot.readListBegin();
assertTrue(l.size == 2);
assertTrue(prot.readString().equals("elem1"));
assertTrue(prot.readString().equals("elem2"));
prot.readListEnd();
prot.readFieldEnd();
// shouldl return nulls at end
prot.readFieldBegin();
assertNull(prot.readString());
prot.readFieldEnd();
// shouldl return nulls at end
prot.readFieldBegin();
assertNull(prot.readString());
prot.readFieldEnd();
prot.readStructEnd();
}
use of org.apache.thrift.protocol.TList in project hive by apache.
the class TBinarySortableProtocol method readListBegin.
/**
* This method always return the same instance of TList to avoid creating new
* instances. It is the responsibility of the caller to read the value before
* calling this method again.
*/
@Override
public TList readListBegin() throws TException {
stackLevel++;
tlist = new TList(ORDERED_TYPE, readI32());
if (tlist.size == 0 && lastPrimitiveWasNull()) {
return null;
}
return tlist;
}
use of org.apache.thrift.protocol.TList in project pinpoint by naver.
the class TReplaceListProtocol method writeListBegin.
@Override
public void writeListBegin(TList list) throws TException {
if (!writeFieldBegin) {
protocol.writeListBegin(list);
return;
}
if (writeListDepth == 0 && currentField != null) {
List<ByteArrayOutput> outputs = replaceFields.get(currentField.name);
if (outputs == null) {
throw new TException("not found replace field - " + currentField.name);
}
final TList replaceList = new TList(list.elemType, outputs.size());
protocol.writeListBegin(replaceList);
for (ByteArrayOutput output : outputs) {
try {
final OutputStream out = ((ByteArrayOutputStreamTransport) getTransport()).getByteArrayOutputStream();
output.writeTo(out);
} catch (IOException e) {
throw new TException(e);
}
}
}
writeListDepth++;
}
Aggregations