Example usage for org.apache.thrift.protocol TProtocol readSetEnd

List of usage examples for org.apache.thrift.protocol TProtocol readSetEnd

Introduction

In this page you can find the example usage for org.apache.thrift.protocol TProtocol readSetEnd.

Prototype

public abstract void readSetEnd() throws TException;

Source Link

Usage

From source file:com.ebay.nest.io.sede.dynamic_type.DynamicSerDeTypeSet.java

License:Apache License

/**
 * NOTE: Set is not supported by Hive yet.
 *///w w w .j  a va 2s .c o m
@Override
public Object deserialize(Object reuse, TProtocol iprot)
        throws SerDeException, TException, IllegalAccessException {
    TSet theset = iprot.readSetBegin();
    if (theset == null) {
        return null;
    }
    Set<Object> result;
    if (reuse != null) {
        result = (Set<Object>) reuse;
        result.clear();
    } else {
        result = new HashSet<Object>();
    }
    for (int i = 0; i < theset.size; i++) {
        Object elem = getElementType().deserialize(null, iprot);
        result.add(elem);
    }
    // in theory, the below call isn't needed in non thrift_mode, but let's not
    // get too crazy
    iprot.readSetEnd();
    return result;
}

From source file:net.morimekta.providence.thrift.TProtocolSerializer.java

License:Apache License

private Object readTypedValue(byte tType, PDescriptor type, TProtocol protocol)
        throws TException, SerializerException {
    switch (tType) {
    case TType.BOOL:
        return protocol.readBool();
    case TType.BYTE:
        return protocol.readByte();
    case TType.I16:
        return protocol.readI16();
    case TType.I32:
        if (PType.ENUM == type.getType()) {
            PEnumDescriptor<?> et = (PEnumDescriptor<?>) type;
            PEnumBuilder<?> eb = et.builder();
            int value = protocol.readI32();
            eb.setByValue(value);//from w w  w  . j a v  a2  s .  c  om
            if (!eb.valid() && readStrict) {
                throw new SerializerException("Invalid enum value " + value + " for " + et.getQualifiedName());
            }
            return eb.build();
        } else {
            return protocol.readI32();
        }
    case TType.I64:
        return protocol.readI64();
    case TType.DOUBLE:
        return protocol.readDouble();
    case TType.STRING:
        if (type == PPrimitive.BINARY) {
            ByteBuffer buffer = protocol.readBinary();
            return Binary.wrap(buffer.array());
        }
        return protocol.readString();
    case TType.STRUCT:
        return readMessage(protocol, (PMessageDescriptor<?, ?>) type);
    case TType.LIST:
        TList listInfo = protocol.readListBegin();
        PList<Object> lDesc = (PList<Object>) type;
        PDescriptor liDesc = lDesc.itemDescriptor();

        PList.Builder<Object> list = lDesc.builder();
        for (int i = 0; i < listInfo.size; ++i) {
            list.add(readTypedValue(listInfo.elemType, liDesc, protocol));
        }

        protocol.readListEnd();
        return list.build();
    case TType.SET:
        TSet setInfo = protocol.readSetBegin();
        PSet<Object> sDesc = (PSet<Object>) type;
        PDescriptor siDesc = sDesc.itemDescriptor();

        PSet.Builder<Object> set = sDesc.builder();
        for (int i = 0; i < setInfo.size; ++i) {
            set.add(readTypedValue(setInfo.elemType, siDesc, protocol));
        }

        protocol.readSetEnd();
        return set.build();
    case TType.MAP:
        TMap mapInfo = protocol.readMapBegin();
        PMap<Object, Object> mDesc = (PMap<Object, Object>) type;
        PDescriptor mkDesc = mDesc.keyDescriptor();
        PDescriptor miDesc = mDesc.itemDescriptor();

        PMap.Builder<Object, Object> map = mDesc.builder();
        for (int i = 0; i < mapInfo.size; ++i) {
            Object key = readTypedValue(mapInfo.keyType, mkDesc, protocol);
            Object val = readTypedValue(mapInfo.valueType, miDesc, protocol);
            map.put(key, val);
        }

        protocol.readMapEnd();
        return map.build();
    default:
        throw new SerializerException("Unsupported protocol field type: " + tType);
    }
}

From source file:org.apache.cassandra.thrift.BatchMutateResult.java

License:Apache License

public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
    org.apache.thrift.protocol.TField field;
    iprot.readStructBegin();// w ww. j av  a2 s  .c  om
    while (true) {
        field = iprot.readFieldBegin();
        if (field.type == org.apache.thrift.protocol.TType.STOP) {
            break;
        }
        switch (field.id) {
        case 1: // DEPS
            if (field.type == org.apache.thrift.protocol.TType.SET) {
                {
                    org.apache.thrift.protocol.TSet _set126 = iprot.readSetBegin();
                    this.deps = new HashSet<Dep>(2 * _set126.size);
                    for (int _i127 = 0; _i127 < _set126.size; ++_i127) {
                        Dep _elem128; // required
                        _elem128 = new Dep();
                        _elem128.read(iprot);
                        this.deps.add(_elem128);
                    }
                    iprot.readSetEnd();
                }
            } else {
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
            }
            break;
        case 2: // LTS
            if (field.type == org.apache.thrift.protocol.TType.I64) {
                this.lts = iprot.readI64();
                setLtsIsSet(true);
            } else {
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
            }
            break;
        default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
        }
        iprot.readFieldEnd();
    }
    iprot.readStructEnd();

    // check for required fields of primitive type, which can't be checked in the validate method
    validate();
}

From source file:org.apache.cassandra.thrift.CountWithMetadata.java

License:Apache License

public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
    org.apache.thrift.protocol.TField field;
    iprot.readStructBegin();// ww w.  ja  va2s .  co  m
    while (true) {
        field = iprot.readFieldBegin();
        if (field.type == org.apache.thrift.protocol.TType.STOP) {
            break;
        }
        switch (field.id) {
        case 1: // COUNT
            if (field.type == org.apache.thrift.protocol.TType.I32) {
                this.count = iprot.readI32();
                setCountIsSet(true);
            } else {
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
            }
            break;
        case 2: // EARLIEST_VALID_TIME
            if (field.type == org.apache.thrift.protocol.TType.I64) {
                this.earliest_valid_time = iprot.readI64();
                setEarliest_valid_timeIsSet(true);
            } else {
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
            }
            break;
        case 3: // LATEST_VALID_TIME
            if (field.type == org.apache.thrift.protocol.TType.I64) {
                this.latest_valid_time = iprot.readI64();
                setLatest_valid_timeIsSet(true);
            } else {
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
            }
            break;
        case 4: // DEPS
            if (field.type == org.apache.thrift.protocol.TType.SET) {
                {
                    org.apache.thrift.protocol.TSet _set109 = iprot.readSetBegin();
                    this.deps = new HashSet<Dep>(2 * _set109.size);
                    for (int _i110 = 0; _i110 < _set109.size; ++_i110) {
                        Dep _elem111; // required
                        _elem111 = new Dep();
                        _elem111.read(iprot);
                        this.deps.add(_elem111);
                    }
                    iprot.readSetEnd();
                }
            } else {
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
            }
            break;
        default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
        }
        iprot.readFieldEnd();
    }
    iprot.readStructEnd();

    // check for required fields of primitive type, which can't be checked in the validate method
    validate();
}

From source file:org.apache.cassandra.thrift.GetCountResult.java

License:Apache License

public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException {
    org.apache.thrift.protocol.TField field;
    iprot.readStructBegin();//from   w  w  w  .  j  a  va  2  s  .  c om
    while (true) {
        field = iprot.readFieldBegin();
        if (field.type == org.apache.thrift.protocol.TType.STOP) {
            break;
        }
        switch (field.id) {
        case 1: // VALUE
            if (field.type == org.apache.thrift.protocol.TType.I32) {
                this.value = iprot.readI32();
                setValueIsSet(true);
            } else {
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
            }
            break;
        case 2: // DEPS
            if (field.type == org.apache.thrift.protocol.TType.SET) {
                {
                    org.apache.thrift.protocol.TSet _set96 = iprot.readSetBegin();
                    this.deps = new HashSet<Dep>(2 * _set96.size);
                    for (int _i97 = 0; _i97 < _set96.size; ++_i97) {
                        Dep _elem98; // required
                        _elem98 = new Dep();
                        _elem98.read(iprot);
                        this.deps.add(_elem98);
                    }
                    iprot.readSetEnd();
                }
            } else {
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
            }
            break;
        case 3: // LTS
            if (field.type == org.apache.thrift.protocol.TType.I64) {
                this.lts = iprot.readI64();
                setLtsIsSet(true);
            } else {
                org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
            }
            break;
        default:
            org.apache.thrift.protocol.TProtocolUtil.skip(iprot, field.type);
        }
        iprot.readFieldEnd();
    }
    iprot.readStructEnd();

    // check for required fields of primitive type, which can't be checked in the validate method
    validate();
}

From source file:org.apache.parquet.thrift.BufferedProtocolReadToWrite.java

License:Apache License

private boolean readOneSet(TProtocol in, List<Action> buffer, SetType expectedType) throws TException {
    final TSet set = in.readSetBegin();
    buffer.add(new Action() {
        @Override//from   w w w .  j a v  a2s. com
        public void write(TProtocol out) throws TException {
            out.writeSetBegin(set);
        }

        @Override
        public String toDebugString() {
            return "<e=" + set.elemType + ", s=" + set.size + ">{*";
        }
    });

    boolean hasFieldsIgnored = readCollectionElements(in, set.size, set.elemType, buffer,
            expectedType.getValues().getType());
    in.readSetEnd();
    buffer.add(SET_END);
    return hasFieldsIgnored;
}

From source file:org.apache.parquet.thrift.ProtocolReadToWrite.java

License:Apache License

private void readOneSet(TProtocol in, TProtocol out) throws TException {
    final TSet set = in.readSetBegin();
    out.writeSetBegin(set);// w w w.jav a2 s . c  om
    readCollectionElements(in, out, set.size, set.elemType);
    in.readSetEnd();
    out.writeSetEnd();
}