Example #1
0
        public IMessage Decode(byte[] data)
        {
            uint     id;
            IMessage msg;

            PBCodec.Decode(data, msgtype_query_, out msg, out id);
            return(msg);
        }
Example #2
0
        public byte[] Encode(IMessage msg)
        {
            uint id = msgid_query_(msg.GetType());

            return((uint.MaxValue != id) ?
                   PBCodec.Encode(id, msg) :
                   null);
        }
Example #3
0
        public object Decode(byte[] data)
        {
            int    id;
            object msg;

            PBCodec.Decode(data, msgtype_query_, out msg, out id);
            return(msg);
        }
Example #4
0
        public byte[] Encode(object msg)
        {
            int id = msgid_query_(msg.GetType());

            return((id > 0) ?
                   PBCodec.Encode(id, msg) :
                   null);
        }
Example #5
0
        private bool Build(IMessage msg, out byte[] data)
        {
            uint id = msgid_query_(msg.GetType());

            if (uint.MaxValue != id)
            {
                data = PBCodec.Encode(id, msg);
                return(null != data);
            }
            else
            {
                data = null;
                return(false);
            }
        }
Example #6
0
        private bool Build(object msg, out byte[] data)
        {
            int id = msgid_query_(msg.GetType());

            if (id > 0)
            {
                data = PBCodec.Encode(id, msg);
                return(null != data);
            }
            else
            {
                data = null;
                return(false);
            }
        }
Example #7
0
        public void Dispatch(int from_handle, uint seq, byte[] data)
        {
            uint     id;
            IMessage msg;

            if (PBCodec.Decode(data, msgtype_query_, out msg, out id))
            {
                IPBHandler h;
                if (handlers_.TryGetValue(id, out h))
                {
                    h.Execute(msg, this, from_handle, seq);
                }
                else if (null != default_handler_)
                {
                    default_handler_(msg, this, from_handle, seq);
                }
            }
        }