示例#1
0
 protected virtual object DecodeData(IObjectInput input)
 {
     try
     {
         return input.ReadObject();
     }
     catch (Exception e)
     {
         throw new IOException("ClassNotFoundException: " + e);
     }
 }
示例#2
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);
        }
示例#3
0
 protected virtual object DecodeResponseData(IChannel channel, IObjectInput input, object requestData)
 {
     return(DecodeResponseData(channel, input));
 }
示例#4
0
 protected virtual object DecodeResponseData(IChannel channel, IObjectInput input)
 {
     return(DecodeResponseData(input));
 }
示例#5
0
 protected virtual object DecodeEventData(IChannel channel, IObjectInput input)
 {
     return(input.ReadObject());
 }
示例#6
0
 protected override object DecodeData(IChannel channel, IObjectInput input)
 {
     return(DecodeRequestData(channel, input));
 }
示例#7
0
 protected virtual object DecodeResponseData(IObjectInput input)
 {
     return(input.ReadObject());
 }
示例#8
0
 protected override object DecodeData(IObjectInput input)
 {
     return(DecodeRequestData(input));
 }
示例#9
0
        protected virtual object DecodeBody(IChannel channel, MemoryStream input, byte[] header)
        {
            byte           flag = header[2], proto = (byte)(flag & SerializationMask);
            ISerialization s        = GetSerialization(channel);
            IObjectInput   inStream = s.Deserialize(input);
            // get request id.
            long id = ByteUtil.Bytes2Long(header, 4);

            if ((flag & FlagRequest) == 0)
            {
                // decode response.
                Response res = new Response(id);
                if ((flag & FlagEvent) != 0)
                {
                    res.SetEvent(Response.HeartbeatEvent);
                }
                // get status.
                byte status = header[3];
                res.Mstatus = status;
                if (status == Response.Ok)
                {
                    try
                    {
                        object data;
                        if (res.IsHeartBeat())
                        {
                            data = DecodeEventData(channel, inStream);
                        }
                        else if (res.Mevent)
                        {
                            data = DecodeEventData(channel, inStream);
                        }
                        else
                        {
                            data = DecodeResponseData(channel, inStream);
                        }
                        res.Mresult = data;
                    }
                    catch (Exception t)
                    {
                        res.Mstatus   = Response.ClientError;
                        res.MerrorMsg = t.ToString();
                    }
                }
                else
                {
                    res.MerrorMsg = inStream.ReadUTF();
                }
                return(res);
            }

            // decode request.
            Request req = new Request(id);

            req.Mversion = "2.0.0";
            req.IsTwoWay = (flag & FlagRequest) != 0;
            if ((flag & FlagEvent) != 0)
            {
                req.SetEvent(Request.HeartBeatEvent);
            }
            try
            {
                object data;
                if (req.IsHeartbeat())
                {
                    data = DecodeEventData(channel, inStream);
                }
                else if (req.IsEvent)
                {
                    data = DecodeEventData(channel, inStream);
                }
                else
                {
                    data = DecodeRequestData(channel, inStream);
                }

                req.Mdata = data;
            }
            catch (Exception t)
            {
                // bad request
                req.IsBroken = true;
                req.Mdata    = t;
            }
            return(req);
        }
示例#10
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);
        }
示例#11
0
 protected virtual object DecodeData(IChannel channel, IObjectInput input)
 {
     return DecodeData(input);
 }