Esempio n. 1
0
        public object Decode(IChannel channel, MemoryStream input)
        {
            IObjectInput inputo = CodecSupport.GetSerialization(channel.Url, _serializationType)
                                  .Deserialize(input);

            byte flag = inputo.ReadByte();

            switch (flag)
            {
            case DubboCodec.ResponseNullValue:
                break;

            case DubboCodec.ResponseValue:
                try
                {
                    Type[] returnType = RpcUtils.GetReturnTypes(_invocation);
                    Value = (returnType == null || returnType.Length == 0 ? inputo.ReadObject() :

                             (returnType.Length == 1 ? inputo.ReadObject(returnType[0])
                                            : inputo.ReadObject(returnType[0])));
                }
                catch (Exception e)
                {
                    throw new IOException("Read response data failed." + e);
                }
                break;

            case DubboCodec.ResponseWithException:
                try
                {
                    object obj = inputo.ReadObject();
                    if (obj is Exception == false)
                    {
                        throw new IOException("Response data error, expect Throwable, but get " + obj);
                    }
                    Exception = ((Exception)obj);
                }
                catch (Exception e)
                {
                    throw new IOException("Read response data failed." + e);
                }
                break;

            default:
                throw new IOException("Unknown result flag, expect '0' '1' '2', get " + flag);
            }
            return(this);
        }