Exemplo 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);
        }
Exemplo n.º 2
0
 protected virtual object DecodeData(IObjectInput input)
 {
     try
     {
         return input.ReadObject();
     }
     catch (Exception e)
     {
         throw new IOException("ClassNotFoundException: " + e);
     }
 }
Exemplo n.º 3
0
 protected virtual object DecodeEventData(IChannel channel, IObjectInput input)
 {
     return(input.ReadObject());
 }
Exemplo n.º 4
0
 protected virtual object DecodeResponseData(IObjectInput input)
 {
     return(input.ReadObject());
 }
Exemplo n.º 5
0
        public object Decode(IChannel channel, MemoryStream input)
        {
            IObjectInput inputo = CodecSupport.GetSerialization(channel.Url, _serializationType)
                                  .Deserialize(input);

            SetAttachment(Constants.DubboVersionKey, inputo.ReadUTF());
            SetAttachment(Constants.PathKey, inputo.ReadUTF());
            SetAttachment(Constants.VersionKey, inputo.ReadUTF());

            MethodName = (inputo.ReadUTF());
            try
            {
                object[] args;
                Type[]   pts;
                string   desc = inputo.ReadUTF();
                if (desc.Length == 0)
                {
                    pts  = DubboCodec.EmptyClassArray;
                    args = DubboCodec.EmptyObjectArray;
                }
                else
                {
                    pts  = ReflectUtil.Desc2ClassArray(desc);
                    args = new object[pts.Length];
                    for (int i = 0; i < args.Length; i++)
                    {
                        try
                        {
                            args[i] = inputo.ReadObject(pts[i]);
                        }
                        catch (Exception)
                        {
                            //
                        }
                    }
                }
                ParameterTypes = (pts);

                Dictionary <string, string> map = inputo.ReadObject <Dictionary <string, string> >();
                if (map != null && map.Count > 0)
                {
                    Dictionary <string, string> attachment = Attachments;
                    if (attachment == null)
                    {
                        attachment = new Dictionary <string, string>();
                    }

                    foreach (var kv in map)
                    {
                        attachment.Add(kv.Key, kv.Value);
                    }

                    Attachments = attachment;
                }
                //decode argument ,may be callback
                for (int i = 0; i < args.Length; i++)
                {
                    args[i] = inputo.ReadObject();
                }

                Arguments = args;
            } catch (Exception e) {
                throw new IOException("Read invocation data failed." + e);
            } finally {
            }
            return(this);
        }