Esempio n. 1
0
        protected override Decimal OnRead(TProtocolReader reader)
        {
            string  v  = reader.ReadString();
            Decimal dc = default(Decimal);

            Decimal.TryParse(v, out dc);
            return(dc);
        }
Esempio n. 2
0
        protected override Guid OnRead(TProtocolReader reader)
        {
            string v  = reader.ReadString();
            Guid   id = Guid.Empty;

            Guid.TryParse(v, out id);
            return(id);
        }
Esempio n. 3
0
        private Object[] ReadArguments(TProtocol inProtocol)
        {
            try
            {
                int             numArgs = _method.GetParameters().Length;
                Object[]        args    = new Object[numArgs];
                TProtocolReader reader  = new TProtocolReader(inProtocol);

                // 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();

                    IThriftCodec codec = null;
                    if (!_parameterCodecs.TryGetValue(fieldId, out codec))
                    {
                        // 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[_thriftParameterIdToCSharpArgument[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;
                foreach (ThriftFieldMetadata argument in _parameters)
                {
                    if (args[argumentPosition] == null)
                    {
                        Type argumentType = argument.ThriftType.CSharpType;

                        if (!argumentType.Equals(typeof(void)))
                        {
                            args[argumentPosition] = ThriftyUtilities.GetDefaultValue(argumentType);
                        }
                    }
                    argumentPosition++;
                }

                return(args);
            }
            catch (TProtocolException e)
            {
                // TProtocolException is the only recoverable exception
                // Other exceptions may have left the input stream in corrupted state so we must
                // tear down the socket.
                throw new TApplicationException(TApplicationException.ExceptionType.ProtocolError, e.Message);
            }
        }
        public override T Read(TProtocol protocol)
        {
            TProtocolReader reader = new TProtocolReader(protocol);

            reader.ReadStructBegin();

            IDictionary <short, Object> data = new Dictionary <short, Object>(_metadata.Fields.Count());

            while (reader.NextField())
            {
                short fieldId = reader.GetFieldId();

                // do we have a codec for this field
                IThriftCodec codec;
                if (!_fields.TryGetValue(fieldId, out codec))
                {
                    reader.SkipFieldData();
                    continue;
                }

                // is this field readable
                ThriftFieldMetadata field = _metadata.GetField(fieldId);
                if (field.ReadOnly || field.Type != FieldKind.ThriftField)
                {
                    reader.SkipFieldData();
                    continue;
                }

                // read the value
                Object value = reader.ReadField(codec);
                if (value == null)
                {
                    if (field.Required == ThriftFieldAttribute.Requiredness.Required)
                    {
                        throw new TProtocolException($"'{field.Name}(id: {fieldId})' is a required field, but it was not set, thrift type: '{field.ThriftType.ToString()}', codec: '{codec.GetType().Name}'");
                    }
                    else
                    {
                        continue;
                    }
                }
                data[fieldId] = value;
            }
            reader.ReadStructEnd();

            // build the struct
            return(ConstructStruct(data));
        }
Esempio n. 5
0
        private Object ReadResponse(TProtocol inProtocol)
        {
            TProtocolReader reader = new TProtocolReader(inProtocol);

            reader.ReadStructBegin();
            Object    results   = null;
            Exception exception = null;

            while (reader.NextField())
            {
                if (reader.GetFieldId() == 0)
                {
                    results = reader.ReadField(_successCodec);
                }
                else
                {
                    IThriftCodec exceptionCodec = null;
                    if (_exceptionCodecs.TryGetValue(reader.GetFieldId(), out exceptionCodec))
                    {
                        exception = (Exception)reader.ReadField(exceptionCodec);
                    }
                    else
                    {
                        reader.SkipFieldData();
                    }
                }
            }
            reader.ReadStructEnd();
            inProtocol.ReadMessageEnd();

            if (exception != null)
            {
                throw exception;
            }

            if (_successCodec.Type == ThriftType.Void)
            {
                // TODO: check for non-null return from a void function?
                return(null);
            }

            if (results == null)
            {
                throw new TApplicationException(TApplicationException.ExceptionType.MissingResult, $"{this.QualifiedName} failed: unknown result");
            }
            return(results);
        }
        protected override DateTime[] OnRead(TProtocolReader reader)
        {
            var longArray = reader.ReadI64Array();

            if (longArray == null)
            {
                return(null);
            }
            else
            {
                DateTime[] result = new DateTime[longArray.Length];
                for (var i = 0; i < longArray.Length; i++)
                {
                    result[i] = DateTimeThriftCodec.FromLongValue(longArray[i]);
                }
                return(result);
            }
        }
Esempio n. 7
0
 protected override short OnRead(TProtocolReader reader)
 {
     return(reader.ReadI16());
 }
Esempio n. 8
0
 protected override long[] OnRead(TProtocolReader reader)
 {
     return(reader.ReadI64Array());
 }
Esempio n. 9
0
 protected override ISet <T> OnRead(TProtocolReader reader)
 {
     return(reader.ReadSet(_elementCodec));
 }
Esempio n. 10
0
 protected override int OnRead(TProtocolReader reader)
 {
     return(reader.ReadI32());
 }
Esempio n. 11
0
        protected override IEnumerable <T> OnRead(TProtocolReader reader)
        {
            var list = reader.ReadList(elementCodec);

            return(_isArray ? list.ToArray() : list);
        }
Esempio n. 12
0
 protected override byte[] OnRead(TProtocolReader reader)
 {
     return(reader.ReadBinary());
 }
Esempio n. 13
0
 protected override long OnRead(TProtocolReader reader)
 {
     return(reader.ReadI64());
 }
Esempio n. 14
0
 protected override bool OnRead(TProtocolReader reader)
 {
     return(reader.ReadBool());
 }
Esempio n. 15
0
 protected override bool[] OnRead(TProtocolReader reader)
 {
     return(reader.ReadBoolArray());
 }
Esempio n. 16
0
 protected override float[] OnRead(TProtocolReader reader)
 {
     return(reader.ReadDoubleArray().Select(d => (float)d).ToArray());;
 }
Esempio n. 17
0
 protected override double OnRead(TProtocolReader reader)
 {
     return(reader.ReadDouble());
 }
Esempio n. 18
0
 protected override double[] OnRead(TProtocolReader reader)
 {
     return(reader.ReadDoubleArray());
 }
Esempio n. 19
0
 protected abstract T OnRead(TProtocolReader reader);
Esempio n. 20
0
 protected override float OnRead(TProtocolReader reader)
 {
     return((float)reader.ReadDouble());
 }
Esempio n. 21
0
        protected override DateTime OnRead(TProtocolReader reader)
        {
            long value = reader.ReadI64();

            return(FromLongValue(value));
        }
Esempio n. 22
0
 protected override IDictionary <K, V> OnRead(TProtocolReader reader)
 {
     return(reader.ReadMap(_keyCodec, _valueCodec));
 }
Esempio n. 23
0
 protected override byte OnRead(TProtocolReader reader)
 {
     return(reader.ReadByte());
 }
Esempio n. 24
0
 protected override int[] OnRead(TProtocolReader reader)
 {
     return(reader.ReadI32Array());
 }
Esempio n. 25
0
 protected override string OnRead(TProtocolReader reader)
 {
     return(reader.ReadString());
 }
Esempio n. 26
0
 protected override short[] OnRead(TProtocolReader reader)
 {
     return(reader.ReadI16Array());
 }