Beispiel #1
0
        public bool Request(string proto, SpObject args, int session, SpStream stream)
        {
            SpStream encode_stream = EncodeRequest(proto, args, session);

            encode_stream.Position = 0;
            return(SpPacker.Pack(encode_stream, stream));
        }
Beispiel #2
0
        public SpRpcResult Dispatch(SpStream stream)
        {
            SpStream unpack_stream = SpPacker.Unpack(stream);

            unpack_stream.Position = 0;
            SpObject header = mHostTypeManager.Codec.Decode(mHeaderType, unpack_stream);

            int session = 0;

            if (header["session"] != null)
            {
                session = header["session"].AsInt();
            }

            int ud = 0;

            if (header["ud"] != null)
            {
                ud = header["ud"].AsInt();
            }

            if (header["type"] != null)
            {
                // handle request
                SpProtocol protocol = mHostTypeManager.GetProtocolByTag(header["type"].AsInt());
                SpObject   obj      = mHostTypeManager.Codec.Decode(protocol.Request, unpack_stream);
                if (session != 0)
                {
                    mSessions[session] = protocol;
                }

                return(new SpRpcResult(session, protocol, SpRpcOp.Request, obj, ud));
            }
            else
            {
                // handle response
                if (mSessions.ContainsKey(session) == false)
                {
                    return(new SpRpcResult());
                }

                SpProtocol protocol = mSessions[session];
                mSessions.Remove(session);

                if (protocol == null)
                {
                    return(new SpRpcResult());
                }

                if (protocol.Response == null)
                {
                    return(new SpRpcResult(session, protocol, SpRpcOp.Response, null, ud));
                }

                SpObject obj = mAttachTypeManager.Codec.Decode(protocol.Response, unpack_stream);
                return(new SpRpcResult(session, protocol, SpRpcOp.Response, obj, ud));
            }
        }
Beispiel #3
0
        public SpStream Response(int session, SpObject args)
        {
            SpObject header = new SpObject();

            header.Insert("session", session);

            SpStream encode_stream = new SpStream();

            mHostTypeManager.Codec.Encode(mHeaderType, header, encode_stream);

            if (session != 0 && mSessions.ContainsKey(session))
            {
                mHostTypeManager.Codec.Encode(mSessions[session].Response, args, encode_stream);
            }

            SpStream pack_stream = new SpStream();

            encode_stream.Position = 0;
            SpPacker.Pack(encode_stream, pack_stream);

            pack_stream.Position = 0;
            return(pack_stream);
        }