Examples of TProtocolReader


Examples of com.facebook.swift.codec.internal.TProtocolReader

    @Override
    public double[] read(TProtocol protocol)
            throws Exception
    {
        checkNotNull(protocol, "protocol is null");
        return new TProtocolReader(protocol).readDoubleArray();
    }
View Full Code Here

Examples of com.facebook.swift.codec.internal.TProtocolReader

    @Override
    public UnionField read(TProtocol protocol)
            throws Exception
    {
        TProtocolReader reader = new TProtocolReader(protocol);

        UnionField field = new UnionField();
        reader.readStructBegin();

        boolean consumed = false;
        while(reader.nextField()) {
            Preconditions.checkState(!consumed, "already consumed");

            field._id = reader.getFieldId();
            switch (field._id) {
            case 1:
                field.stringValue = reader.readStringField();
                consumed = true;
                break;
            case 2:
                field.longValue = reader.readI64Field();
                consumed = true;
                break;
            case 3:
                field.fruitValue = reader.readEnumField(fruitCodec);
                consumed = true;
                break;
            default:
                field._id = -1;
                reader.skipFieldData();
            }
        }
        reader.readStructEnd();

        return field;
    }
View Full Code Here

Examples of com.facebook.swift.codec.internal.TProtocolReader

    @Override
    public BonkField read(TProtocol protocol)
            throws Exception
    {
        TProtocolReader reader = new TProtocolReader(protocol);

        String message = null;
        int type = 0;

        reader.readStructBegin();

        while (reader.nextField()) {
            switch (reader.getFieldId()) {
                case 1:
                    message = reader.readStringField();
                    break;
                case 2:
                    type = reader.readI32Field();
                    break;
                default:
                    reader.skipFieldData();
            }
        }
        reader.readStructEnd();

        BonkField bonkField = new BonkField();
        if (message != null) {
            bonkField.message = message;
        }
View Full Code Here

Examples of com.facebook.swift.codec.internal.TProtocolReader

    @Override
    public ArrayField read(TProtocol protocol)
            throws Exception
    {
        TProtocolReader reader = new TProtocolReader(protocol);

        boolean[] booleanArray = null;
        short[] shortArray = null;
        int[] intArray = null;
        long[] longArray = null;
        double[] doubleArray = null;
        byte[] byteArray = null;

        reader.readStructBegin();

        while (reader.nextField()) {
            switch (reader.getFieldId()) {
                case 1:
                    booleanArray = reader.readBoolArrayField();
                    break;
                case 2:
                    shortArray = reader.readI16ArrayField();
                    break;
                case 3:
                    intArray = reader.readI32ArrayField();
                    break;
                case 4:
                    longArray = reader.readI64ArrayField();
                    break;
                case 5:
                    doubleArray = reader.readDoubleArrayField();
                    break;
                case 6:
                    byteArray = reader.readBinaryField().array();
                    break;
                default:
                    reader.skipFieldData();
            }
        }
        reader.readStructEnd();

        ArrayField arrayField = new ArrayField();
        if (booleanArray != null) {
            arrayField.booleanArray = booleanArray;
        }
View Full Code Here

Examples of com.facebook.swift.codec.internal.TProtocolReader

    @Override
    public T read(TProtocol protocol)
            throws Exception
    {
        TProtocolReader reader = new TProtocolReader(protocol);
        reader.readStructBegin();

        Map<Short, Object> data = new HashMap<>(metadata.getFields().size());
        while (reader.nextField()) {
            short fieldId = reader.getFieldId();

            // do we have a codec for this field
            ThriftCodec<?> codec = fields.get(fieldId);
            if (codec == null) {
                reader.skipFieldData();
                continue;
            }

            // is this field readable
            ThriftFieldMetadata field = metadata.getField(fieldId);
            if (field.isReadOnly() || field.getType() != THRIFT_FIELD) {
                reader.skipFieldData();
                continue;
            }

            // read the value
            Object value = reader.readField(codec);
            if (value == null) {
              if (field.getRequiredness() == ThriftField.Requiredness.REQUIRED) {
                throw new TProtocolException("required field was not set");
              } else {
                continue;
              }
            }

            data.put(fieldId, value);
        }
        reader.readStructEnd();

        // build the struct
        return constructStruct(data);
    }
View Full Code Here

Examples of com.facebook.swift.codec.internal.TProtocolReader

    @Override
    public T read(TProtocol protocol)
            throws Exception
    {
        TProtocolReader reader = new TProtocolReader(protocol);
        reader.readStructBegin();

        Map.Entry<Short, Object> data = null;
        Short fieldId = null;
        while (reader.nextField()) {
            checkState(fieldId == null, "Received Union with more than one value (seen id %s, now id %s)", fieldId, reader.getFieldId());

            fieldId = reader.getFieldId();

            // do we have a codec for this field
            ThriftCodec<?> codec = fields.get(fieldId);
            if (codec == null) {
                reader.skipFieldData();
            }
            else {

                // is this field readable
                ThriftFieldMetadata field = metadata.getField(fieldId);
                if (field.isWriteOnly() || field.getType() != THRIFT_FIELD) {
                    reader.skipFieldData();
                    continue;
                }

                // read the value
                Object value = reader.readField(codec);
                if (value == null) {
                    continue;
                }

                data = Maps.immutableEntry(fieldId, value);
            }
        }
        reader.readStructEnd();

        // build the struct
        return constructStruct(data);
    }
View Full Code Here

Examples of com.facebook.swift.codec.internal.TProtocolReader

    @Override
    public Set<T> read(TProtocol protocol)
            throws Exception
    {
        Preconditions.checkNotNull(protocol, "protocol is null");
        return new TProtocolReader(protocol).readSet(elementCodec);
    }
View Full Code Here

Examples of com.facebook.swift.codec.internal.TProtocolReader

    @Override
    public List<T> read(TProtocol protocol)
            throws Exception
    {
        Preconditions.checkNotNull(protocol, "protocol is null");
        return new TProtocolReader(protocol).readList(elementCodec);
    }
View Full Code Here

Examples of com.facebook.swift.codec.internal.TProtocolReader

    @Override
    public Map<K, V> read(TProtocol protocol)
            throws Exception
    {
        Preconditions.checkNotNull(protocol, "protocol is null");
        return new TProtocolReader(protocol).readMap(keyCodec, valueCodec);
    }
View Full Code Here

Examples of com.facebook.swift.codec.internal.TProtocolReader

    @Override
    public T read(TProtocol protocol)
            throws Exception
    {
        TProtocolReader reader = new TProtocolReader(protocol);
        reader.readStructBegin();

        Map<Short, Object> data = new HashMap<>(metadata.getFields().size());
        while (reader.nextField()) {
            short fieldId = reader.getFieldId();

            // do we have a codec for this field
            ThriftCodec<?> codec = fields.get(fieldId);
            if (codec == null) {
                reader.skipFieldData();
                continue;
            }

            // is this field readable
            ThriftFieldMetadata field = metadata.getField(fieldId);
            if (field.isReadOnly() || field.getType() != THRIFT_FIELD) {
                reader.skipFieldData();
                continue;
            }

            // read the value
            Object value = reader.readField(codec);
            if (value == null) {
                continue;
            }

            data.put(fieldId, value);
        }
        reader.readStructEnd();

        // build the struct
        return constructStruct(data);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.