コード例 #1
0
ファイル: Protocol.cs プロジェクト: fengqk/Art
        public static Protocol Decode(Octets content)
        {
			Protocol prtc = null;
            int iType = 0;
            OctetsStream os = new OctetsStream(content);
            OctetsStream data = new OctetsStream();

            try
            {
                os.Begin();
                iType = (int)os.uncompact_uint32();
                os.unmarshal(data);
                os.Commit();

				prtc = Create(iType);
				if (prtc == null)
				{
					prtc = new ProtocolDefault();
				    Debug.Log(string.Format("Protocol type {0} not found", (NetProtocolType)iType));
				}
				else
					prtc.unmarshal(data);
            }
            catch (MarshalException)
            {
                os.Rollback();
                Debug.Log(string.Format("Protocol decode error, type {0}", (NetProtocolType)iType));
                prtc = null;
            }

            return prtc;
        }