in core/src/main/java/com/twitter/elephantbird/util/ThriftUtils.java [333:384]
public static Object readFieldNoTag(TProtocol proto,
Field field)
throws TException {
Collection<Object> coll = null;
Field innerField = null;
switch (field.getType()) {
case TType.LIST:
innerField = field.getListElemField();
coll = Lists.newArrayList(); break;
case TType.SET:
innerField = field.getSetElemField();
coll = Sets.newHashSet(); break;
case TType.MAP:
innerField = field.getMapKeyField(); break;
default:
return readSingleFieldNoTag(proto, field);
}
// collection or a map:
if (field.getType() == TType.MAP) {
proto.readByte();
proto.readByte();
int nEntries = proto.readI32();
Map<Object, Object> map = Maps.newHashMap();
Field valueField = field.getMapValueField();
for (int i=0; i<nEntries; i++) {
map.put(readFieldNoTag(proto, innerField),
readFieldNoTag(proto, valueField));
}
return map;
} else { // SET or LIST
proto.readByte();
int nEntries = proto.readI32();
for(int i=0; i<nEntries; i++) {
coll.add(readFieldNoTag(proto, innerField));
}
return coll;
}
}