/** * To consume a list of elements * @param c the type of the list content * @param consumer the consumer that will receive the list * @return a ListConsumer that can be passed to the DelegatingFieldConsumer */ public static <T extends TBase<T,? extends TFieldIdEnum>> ListConsumer listOf(Class<T> c, final Consumer<List<T>> consumer) { class ListConsumer implements Consumer<T> { List<T> list; @Override public void consume(T t) { list.add(t); } } final ListConsumer co = new ListConsumer(); return new DelegatingListElementsConsumer(struct(c, co)) { @Override public void consumeList(TProtocol protocol, EventBasedThriftReader reader, TList tList) throws TException { co.list = new ArrayList<T>(); super.consumeList(protocol, reader, tList); consumer.consume(co.list); } }; }
@Override public Void visit(final ThriftType.ListType listType, Void v) { dummyEvents.add(new ParquetProtocol("readListBegin()") { @Override public TList readListBegin() throws TException { return new TList(); } }); dummyEvents.add(new ParquetProtocol("readListEnd()") { @Override public void readListEnd() throws TException { } }); return null; }
private boolean readOneList(TProtocol in, List<Action> buffer, ListType expectedType) throws TException { final TList list = in.readListBegin(); buffer.add(new Action() { @Override public void write(TProtocol out) throws TException { out.writeListBegin(list); } @Override public String toDebugString() { return "<e=" + list.elemType + ", s=" + list.size + ">{"; } }); boolean hasFieldsIgnored = readCollectionElements(in, list.size, list.elemType, buffer, expectedType.getValues().getType()); in.readListEnd(); buffer.add(LIST_END); return hasFieldsIgnored; }
public void writeListBegin(TList list) throws TException { assertContextIsNotMapKey(LIST); writeContext_.write(); trans_.write(LBRACKET); pushWriteContext(new ListContext()); // No metadata! }
public TList readListBegin() throws TException { BaseArray prevStruct = structStack.peek(); BaseArray obj = prevStruct.getArray(); structStack.push(obj); ListMetaData lm = (ListMetaData) obj.getMetaData(); return new TList(lm.elemMetaData.type, obj.length()); }
@Override public void write(List list, TProtocol protocol) throws TException { protocol.writeListBegin(new TList(valueTypeAdapter.getTType(), list.size())); for (Object o : list) { valueTypeAdapter.write(o, protocol); } protocol.writeListEnd(); }
@Override public List read(TProtocol protocol) throws TException { TList tlist = protocol.readListBegin(); ArrayList arrayList = new ArrayList(tlist.size); for (int i = 0, n = tlist.size; i < n; i++) { arrayList.add(valueTypeAdapter.read(protocol)); } protocol.readListEnd(); return arrayList; }
@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++; }
/** * reads the list content (elements) from the underlying protocol and passes the events to the list event consumer * @param eventConsumer the consumer * @param tList the list descriptor * @throws TException */ public void readListContent(ListConsumer eventConsumer, TList tList) throws TException { for (int i = 0; i < tList.size; i++) { eventConsumer.consumeElement(protocol, this, tList.elemType); } }
@Override void collectionStart(final int count, final byte type) { parentEvents.add(new ParquetProtocol("readListBegin()") { @Override public TList readListBegin() throws TException { return new TList(type, count); } }); }
private void readOneList(TProtocol in, TProtocol out) throws TException { final TList list = in.readListBegin(); out.writeListBegin(list); readCollectionElements(in, out, list.size, list.elemType); in.readListEnd(); out.writeListEnd(); }
public TList readListBegin() throws TException { StructContext context = (StructContext) peekContext(); if(context.fieldsStack.isEmpty()) { return EMPTY_LIST; } String fieldName = context.fieldsStack.peek(); ListContext listContext = new ListContext(); BasicDBList dbList = (BasicDBList) context.dbObject.get(fieldName); listContext.dbList = dbList; listContext.thriftObject = getThriftObject(context.thriftObject, fieldName); pushContext(listContext); return new TList(TType.LIST, dbList.size()); }
@Override public TList readListBegin() throws TException { return new TList((Byte) params.pollFirst(), (Integer) params.pollFirst()); }
@Override public void writeListBegin(TList tList) throws TException { oprot.writeListBegin(tList); }
public void writeListBegin(TList list) throws TException { this.assertContextIsNotMapKey("list"); this.writeContext_.write(); this.trans_.write(LBRACKET); this.pushWriteContext(new TSimpleJSONProtocol.ListContext()); }
public TList readListBegin() throws TException { return EMPTY_LIST; }
@Override public void writeListBegin(TList list) throws TException { writeSequenceBegin(list.size); }
@Override public TList readListBegin() throws TException { int size = readSequenceBegin(); return new TList(UNUSED_TYPE, size); }
@Override public TList readListBegin() throws TException { throw new TException("unsupported operation"); }
public void writeListBegin(TList list) throws TException { delegate.writeListBegin(list); }
public TList readListBegin() throws TException { return delegate.readListBegin(); }
public void consumeList(TProtocol protocol, EventBasedThriftReader reader, TList tList) throws TException { reader.readListContent(this, tList); }
@Override public void writeListBegin(TList list) throws TException { size = list.size; startListWrapper(); }
private String toString(TList list) { return "<TList elemType:" + list.elemType + " size:" + list.size + ">"; }
/** * {@inheritDoc} * @see org.apache.parquet.thrift.ParquetProtocol#writeListBegin(org.apache.thrift.protocol.TList) */ @Override public void writeListBegin(TList list) throws TException { if (LOG.isDebugEnabled()) LOG.debug("writeListBegin("+toString(list)+")"); currentProtocol.writeListBegin(list); }
@Override public void writeListBegin(TList tList) throws TException { }
@Override public TList readListBegin() throws TException { return null; }
@Override public void writeListBegin(TList list) throws TException { throw exception(); }
@Override public TList readListBegin() throws TException { throw exception(); }
public TList readListBegin() throws TException { LOG.debug("readListBegin()"); return next().readListBegin(); }
public void read(TProtocol prot, ThriftSampleData struct) throws TException { TTupleProtocol iprot = (TTupleProtocol)prot; BitSet incoming = iprot.readBitSet(7); if (incoming.get(0)) { struct.id = iprot.readI32(); struct.setIdIsSet(true); } if (incoming.get(1)) { struct.name = iprot.readString(); struct.setNameIsSet(true); } if (incoming.get(2)) { struct.created_at = iprot.readI64(); struct.setCreated_atIsSet(true); } if (incoming.get(3)) { struct.active = iprot.readBool(); struct.setActiveIsSet(true); } int _i25; if (incoming.get(4)) { TList _list16 = new TList((byte)6, iprot.readI32()); struct.groups = new ArrayList(_list16.size); for(_i25 = 0; _i25 < _list16.size; ++_i25) { short _elem17 = iprot.readI16(); struct.groups.add(_elem17); } struct.setGroupsIsSet(true); } String _elem24; if (incoming.get(5)) { TMap _map19 = new TMap((byte)11, (byte)10, iprot.readI32()); struct.map_values = new HashMap(2 * _map19.size); for(int _i22 = 0; _i22 < _map19.size; ++_i22) { _elem24 = iprot.readString(); long _val21 = iprot.readI64(); struct.map_values.put(_elem24, _val21); } struct.setMap_valuesIsSet(true); } if (incoming.get(6)) { TSet _set23 = new TSet((byte)11, iprot.readI32()); struct.set_values = new HashSet(2 * _set23.size); for(_i25 = 0; _i25 < _set23.size; ++_i25) { _elem24 = iprot.readString(); struct.set_values.add(_elem24); } struct.setSet_valuesIsSet(true); } }
public void write(TProtocol oprot, ThriftSampleData struct) throws TException { struct.validate(); oprot.writeStructBegin(ThriftSampleData.STRUCT_DESC); if (struct.isSetId()) { oprot.writeFieldBegin(ThriftSampleData.ID_FIELD_DESC); oprot.writeI32(struct.id); oprot.writeFieldEnd(); } if (struct.name != null && struct.isSetName()) { oprot.writeFieldBegin(ThriftSampleData.NAME_FIELD_DESC); oprot.writeString(struct.name); oprot.writeFieldEnd(); } if (struct.isSetCreated_at()) { oprot.writeFieldBegin(ThriftSampleData.CREATED_AT_FIELD_DESC); oprot.writeI64(struct.created_at); oprot.writeFieldEnd(); } if (struct.isSetActive()) { oprot.writeFieldBegin(ThriftSampleData.ACTIVE_FIELD_DESC); oprot.writeBool(struct.active); oprot.writeFieldEnd(); } Iterator var3; if (struct.groups != null) { oprot.writeFieldBegin(ThriftSampleData.GROUPS_FIELD_DESC); oprot.writeListBegin(new TList((byte)6, struct.groups.size())); var3 = struct.groups.iterator(); while(var3.hasNext()) { short _iter10 = ((Short)var3.next()).shortValue(); oprot.writeI16(_iter10); } oprot.writeListEnd(); oprot.writeFieldEnd(); } if (struct.map_values != null) { oprot.writeFieldBegin(ThriftSampleData.MAP_VALUES_FIELD_DESC); oprot.writeMapBegin(new TMap((byte)11, (byte)10, struct.map_values.size())); var3 = struct.map_values.entrySet().iterator(); while(var3.hasNext()) { Entry<String, Long> _iter11 = (Entry)var3.next(); oprot.writeString((String)_iter11.getKey()); oprot.writeI64(((Long)_iter11.getValue()).longValue()); } oprot.writeMapEnd(); oprot.writeFieldEnd(); } if (struct.set_values != null) { oprot.writeFieldBegin(ThriftSampleData.SET_VALUES_FIELD_DESC); oprot.writeSetBegin(new TSet((byte)11, struct.set_values.size())); var3 = struct.set_values.iterator(); while(var3.hasNext()) { String _iter12 = (String)var3.next(); oprot.writeString(_iter12); } oprot.writeSetEnd(); oprot.writeFieldEnd(); } oprot.writeFieldStop(); oprot.writeStructEnd(); }
public void writeListBegin(TList list) throws TException { pushContext(new ListContext()); }
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(); }