List of usage examples for org.apache.thrift.protocol TTupleProtocol readBitSet
public BitSet readBitSet(int i) throws TException
From source file:net.morimekta.providence.thrift.TTupleProtocolSerializer.java
License:Apache License
private <Message extends PMessage<Message, Field>, Field extends PField> Message readMessage( TTupleProtocol protocol, PMessageDescriptor<Message, Field> descriptor) throws SerializerException, TException { PMessageBuilder<Message, Field> builder = descriptor.builder(); if (descriptor.getVariant() == PMessageVariant.UNION) { int fieldId = protocol.readI16(); PField fld = descriptor.getField(fieldId); builder.set(fld.getKey(), readTypedValue(fld.getDescriptor(), protocol)); } else {// ww w. j a v a 2 s . c o m PField[] fields = descriptor.getFields(); int numOptionals = countOptionals(fields); BitSet optionals = null; int optionalPos = 0; for (PField fld : fields) { if (fld.getRequirement() == PRequirement.REQUIRED) { builder.set(fld.getKey(), readTypedValue(fld.getDescriptor(), protocol)); } else { if (optionals == null) { optionals = protocol.readBitSet(numOptionals); } if (optionals.get(optionalPos)) { builder.set(fld.getKey(), readTypedValue(fld.getDescriptor(), protocol)); } ++optionalPos; } } } if (readStrict) { try { builder.validate(); } catch (IllegalStateException e) { throw new SerializerException(e, e.getMessage()); } } return builder.build(); }