Пример #1
0
        /// <summary>
        /// 데이터를 언마샬 한다.
        /// </summary>
        /// <param name="data">언마샬링할 데이터</param>
        /// <param name="packetManager">패킷 매니저</param>
        /// <returns>생성한 패킷</returns>
        public IPacket Unmarshal(string data, IPacketManager packetManager)
        {
            ePacketId packetId   = ePacketId.Max;
            string    packetData = "";

            int packetIdIndex = data.IndexOf(',');

            if (-1 == packetIdIndex)
            {
                return(null);
            }

            string packetIdData = data.Substring(0, packetIdIndex);

            if (0 == packetIdData.Length)
            {
                return(null);
            }

            packetData = data.Substring(packetIdIndex + 1, data.Length - packetIdData.Length - 1); // ','가 있어서 -1을 하였다.
            packetId   = (ePacketId)Convert.ToInt32(packetIdData);

            IPacket aaa = packetManager.Allocate(packetId, packetData);

            return(aaa);
        }
Пример #2
0
        /// <summary>
        /// 패킷을 할당한다.
        /// </summary>
        /// <param name="packetId">패킷Id</param>
        /// <param name="data">패킷 데이터</param>
        /// <returns>할당된 패킷</returns>
        //public IPacket Allocate(ePacketId packetId, string data)
        //{
        //    if (false == PacketCreator.ContainsKey(packetId))
        //    {
        //        return null;
        //    }

        //    return PacketCreator[packetId].Unmarshal(data);
        //}
        public IPacket Allocate(ePacketId packetId, string data)
        {
            if (false == PacketCreator.ContainsKey(packetId))
            {
                return(null);
            }

            return(PacketCreator[packetId].Unmarshal(data));
        }
        public bool Add(ePacketId packetId, IPacketHandler packetHandler)
        {
            if (true == PacketHandlerMap.ContainsKey(packetId))
            {
                return(false);
            }

            PacketHandlerMap.Add(packetId, packetHandler);
            return(true);
        }