Beispiel #1
0
        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;
        }
Beispiel #2
0
 public OctetsStream unmarshal(OctetsStream os)
 {
     int size = (int)os.uncompact_uint32();
     for (int i = 0; i < size; i++)
     {
         Add(os.unmarshal_Octets());
     }
     return os;
 }