Examples of TProtocolReader


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

            throws Exception
    {
        try {
            int numArgs = method.getParameterTypes().length;
            Object[] args = new Object[numArgs];
            TProtocolReader reader = new TProtocolReader(in);

            // Map incoming arguments from the ID passed in on the wire to the position in the
            // java argument list we expect to see a parameter with that ID.
            reader.readStructBegin();
            while (reader.nextField()) {
                short fieldId = reader.getFieldId();

                ThriftCodec<?> codec = parameterCodecs.get(fieldId);
                if (codec == null) {
                    // unknown field
                    reader.skipFieldData();
                }
                else {
                    // Map the incoming arguments to an array of arguments ordered as the java
                    // code for the handler method expects to see them
                    args[thriftParameterIdToJavaArgumentListPositionMap.get(fieldId)] = reader.readField(codec);
                }
            }
            reader.readStructEnd();

            // Walk through our list of expected parameters and if no incoming parameters were
            // mapped to a particular expected parameter, fill the expected parameter slow with
            // the default for the parameter type.
            int argumentPosition = 0;
View Full Code Here

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

    }

    private Object readResponse(TProtocol in)
            throws Exception
    {
        TProtocolReader reader = new TProtocolReader(in);
        reader.readStructBegin();
        Object results = null;
        Exception exception = null;
        while (reader.nextField()) {
            if (reader.getFieldId() == 0) {
                results = reader.readField(successCodec);
            }
            else {
                ThriftCodec<Object> exceptionCodec = exceptionCodecs.get(reader.getFieldId());
                if (exceptionCodec != null) {
                    exception = (Exception) reader.readField(exceptionCodec);
                }
                else {
                    reader.skipFieldData();
                }
            }
        }
        reader.readStructEnd();
        in.readMessageEnd();

        if (exception != null) {
            throw exception;
        }
View Full Code Here

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

    }

    private Object readResponse(TProtocol in)
            throws Exception
    {
        TProtocolReader reader = new TProtocolReader(in);
        reader.readStructBegin();
        Object results = null;
        Exception exception = null;
        while (reader.nextField()) {
            if (reader.getFieldId() == 0) {
                results = reader.readField(successCodec);
            }
            else {
                ThriftCodec<Object> exceptionCodec = exceptionCodecs.get(reader.getFieldId());
                if (exceptionCodec != null) {
                    exception = (Exception) reader.readField(exceptionCodec);
                }
                else {
                    reader.skipFieldData();
                }
            }
        }
        reader.readStructEnd();
        in.readMessageEnd();

        if (exception != null) {
            throw exception;
        }
View Full Code Here

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

            throws Exception
    {
        try {
            int numArgs = method.getParameterTypes().length;
            Object[] args = new Object[numArgs];
            TProtocolReader reader = new TProtocolReader(in);

            // Map incoming arguments from the ID passed in on the wire to the position in the
            // java argument list we expect to see a parameter with that ID.
            reader.readStructBegin();
            while (reader.nextField()) {
                short fieldId = reader.getFieldId();

                ThriftCodec<?> codec = parameterCodecs.get(fieldId);
                if (codec == null) {
                    // unknown field
                    reader.skipFieldData();
                }
                else {
                    // Map the incoming arguments to an array of arguments ordered as the java
                    // code for the handler method expects to see them
                    args[thriftParameterIdToJavaArgumentListPositionMap.get(fieldId)] = reader.readField(codec);
                }
            }
            reader.readStructEnd();

            // Walk through our list of expected parameters and if no incoming parameters were
            // mapped to a particular expected parameter, fill the expected parameter slow with
            // the default for the parameter type.
            int argumentPosition = 0;
View Full Code Here

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

    private Object readResponse(TProtocol in)
            throws Exception
    {
        long start = nanoTime();

        TProtocolReader reader = new TProtocolReader(in);
        reader.readStructBegin();
        Object results = null;
        Exception exception = null;
        while (reader.nextField()) {
            if (reader.getFieldId() == 0) {
                results = reader.readField(successCodec);
            }
            else {
                ThriftCodec<Object> exceptionCodec = exceptionCodecs.get(reader.getFieldId());
                if (exceptionCodec != null) {
                    exception = (Exception) reader.readField(exceptionCodec);
                }
                else {
                    reader.skipFieldData();
                }
            }
        }
        reader.readStructEnd();
        in.readMessageEnd();

        stats.addReadTime(nanosSince(start));

        if (exception != null) {
View Full Code Here

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

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

        boolean aBoolean = false;
        byte aByte = 0;
        short aShort = 0;
        int aInt = 0;
        long aLong = 0;
        double aDouble = 0;
        String aString = null;
        BonkField aStruct = null;
        Fruit aEnum = null;
        UnionField aUnion = null;

        reader.readStructBegin();

        while (reader.nextField()) {
            switch (reader.getFieldId()) {
                case 1:
                    aBoolean = reader.readBoolField();
                    break;
                case 2:
                    aByte = reader.readByteField();
                    break;
                case 3:
                    aShort = reader.readI16Field();
                    break;
                case 4:
                    aInt = reader.readI32Field();
                    break;
                case 5:
                    aLong = reader.readI64Field();
                    break;
                case 6:
                    aDouble = reader.readDoubleField();
                    break;
                case 7:
                    aString = reader.readStringField();
                    break;
                case 8:
                    aStruct = reader.readStructField(aStructCodec);
                    break;
                case 9:
                    aEnum = reader.readEnumField(aFruitCodec);
                    break;
                case 60:
                    aUnion = reader.readStructField(aUnionCodec);
                default:
                    reader.skipFieldData();
            }
        }
        reader.readStructEnd();

        OneOfEverything oneOfEverything = new OneOfEverything();
        oneOfEverything.aBoolean = aBoolean;
        oneOfEverything.aByte = aByte;
        oneOfEverything.aShort = aShort;
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 = byteBufferToString(reader.readBinaryField());
                    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 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 =  byteBufferToString(reader.readBinaryField());
                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

            throws Exception
    {
        try {
            int numArgs = method.getParameterTypes().length;
            Object[] args = new Object[numArgs];
            TProtocolReader reader = new TProtocolReader(in);

            // Map incoming arguments from the ID passed in on the wire to the position in the
            // java argument list we expect to see a parameter with that ID.
            reader.readStructBegin();
            while (reader.nextField()) {
                short fieldId = reader.getFieldId();

                ThriftCodec<?> codec = parameterCodecs.get(fieldId);
                if (codec == null) {
                    // unknown field
                    reader.skipFieldData();
                }
                else {
                    // Map the incoming arguments to an array of arguments ordered as the java
                    // code for the handler method expects to see them
                    args[thriftParameterIdToJavaArgumentListPositionMap.get(fieldId)] = reader.readField(codec);
                }
            }
            reader.readStructEnd();

            // Walk through our list of expected parameters and if no incoming parameters were
            // mapped to a particular expected parameter, fill the expected parameter slow with
            // the default for the parameter type.
            int argumentPosition = 0;
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.