Exemplo n.º 1
0
        /// <summary>
        /// 注册对于类型是MsgType的消息的处理函数, 例如:
        /// 对于MsgA
        /// c.Register<MsgA>(Handler);
        /// Handler的定义是
        /// void Handler(MsgA msg, PBChannel channel, int src,uint session) { ... }
        /// </summary>
        /// <typeparam name="MsgType">protobuf的消息类型</typeparam>
        /// <param name="f">消息处理函数</param>
        public void Register <MsgType>(PBHandler <MsgType> .F f)
        {
            int id = msgid_query_(typeof(MsgType));

            if (id > 0)
            {
                handlers_[id] = new PBHandler <MsgType>(f);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 注册对于类型是MsgType的消息的处理函数, 例如:
        /// 对于MsgA
        /// c.Register<MsgA>(Handler);
        /// Handler的定义是
        /// void Handler(MsgA msg, PBChannel channel, int src,uint session) { ... }
        /// </summary>
        /// <typeparam name="MsgType">protobuf的消息类型</typeparam>
        /// <param name="f">消息处理函数</param>
        public void Register <MsgType>(PBHandler <MsgType> .F f)
            where MsgType : IMessage
        {
            uint id = msgid_query_(typeof(MsgType));

            if (uint.MaxValue != id)
            {
                handlers_[id] = new PBHandler <MsgType>(f);
            }
        }