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

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

            Guid.TryParse(v, out id);
            return(id);
        }
Exemplo 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));
        }
Exemplo 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);
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 7
0
 protected override short OnRead(TProtocolReader reader)
 {
     return(reader.ReadI16());
 }
Exemplo n.º 8
0
 protected override long[] OnRead(TProtocolReader reader)
 {
     return(reader.ReadI64Array());
 }
Exemplo n.º 9
0
 protected override ISet <T> OnRead(TProtocolReader reader)
 {
     return(reader.ReadSet(_elementCodec));
 }
Exemplo n.º 10
0
 protected override int OnRead(TProtocolReader reader)
 {
     return(reader.ReadI32());
 }
Exemplo n.º 11
0
        protected override IEnumerable <T> OnRead(TProtocolReader reader)
        {
            var list = reader.ReadList(elementCodec);

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

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