Example #1
0
        public Hashtable toMap(byte[] buffer)
        {
            Hashtable r = new Hashtable();

            if (buffer != null)
            {
                MemoryStream ms = new MemoryStream();
                ms.Write(buffer, 0, buffer.Length);
                ms.Position = 0;
                object obj = B2InputStream.readObject(ms);
                if (obj != null && obj is Hashtable)
                {
                    r = (Hashtable)obj;
                }
                else
                {
                    r = new Hashtable();
                }
            }
            else
            {
                r = new Hashtable();
            }
            return(r);
        }
Example #2
0
        private object defaultUnpackMsg(USocket s, MemoryStream buffer)
        {
            object ret      = null;
            long   oldPos   = buffer.Position;
            long   tatalLen = buffer.Length;
            long   needLen  = B2InputStream.readInt(buffer);

            if (needLen <= 0 || needLen > __maxLen)
            {
                // 网络Number据错误。断isOpen网络
                outofLine(s, false);
                s.close();
                return(null);
            }
            long usedLen = buffer.Position;

            if (usedLen + needLen <= tatalLen)
            {
                ret = B2InputStream.readObject(buffer);
            }
            else
            {
                //说明长度不够
                buffer.Position = oldPos;
            }
            return(ret);
        }
Example #3
0
        public static double bio2Double(byte[] buff)
        {
            if (buff == null)
            {
                return(0);
            }
            MemoryStream ms = null;

            try {
                if (buff == null)
                {
                    return(0);
                }
                ms = msPool.borrowObject("");
                ms.Write(buff, 0, buff.Length);
                ms.Position = 0;
                double ret = (double)(B2InputStream.readObject(ms));
                msPool.returnObject(ms);
                return(ret);
            } catch (System.Exception e) {
                //Debug.LogError (e);
                if (ms != null)
                {
                    msPool.returnObject(ms);
                }
                return(0);
            }
        }
Example #4
0
        public static void readFullyBIO2Length(Stream ns)
        {
            int len = B2InputStream.readInt(ns);

            byte[] b = new byte[len];
            readFully(ns, b);
        }
Example #5
0
        /// <summary>
        /// Parses the recived data.解析接收的数据,解析成功后发送给dispatcher
        /// </summary>
        /// <returns>The recived data.</returns>
        /// <param name="buffer">Buffer.</param>
        public virtual object parseRecivedData(MemoryStream buffer)
        {
            object ret    = null;
            long   oldPos = buffer.Position;

            buffer.Position = 0;
            long tatolLen = buffer.Length;
            long needLen  = B2InputStream.readInt(buffer);

            if (needLen <= 0 || needLen > __maxLen)
            {
                // 网络Number据错误。断isOpen网络
                outofLine(this.socket, false);
                //this.stop();
                return(null);
            }
            long usedLen = buffer.Position;

            if (usedLen + needLen <= tatolLen)
            {
                ret = B2InputStream.readObject(buffer);
            }
            else
            {
                //说明长度不够
                buffer.Position = oldPos;
            }
            return(ret);
        }
Example #6
0
 public static object fileToObj(string path)
 {
     if (!File.Exists(path))
     {
         return(null);
     }
     byte[] buffer = File.ReadAllBytes(path);
     if (buffer != null)
     {
         MemoryStream ms = new MemoryStream();
         ms.Write(buffer, 0, buffer.Length);
         ms.Position = 0;
         object obj = B2InputStream.readObject(ms);
         if (obj != null)
         {
             return(obj);
         }
     }
     return(null);
 }
Example #7
0
        public static Hashtable readMaterialTexRefCfg()
        {
            Hashtable ret = null;

#if UNITY_EDITOR
            byte[] buffer = File.Exists(materialTexRefCfgPath) ? File.ReadAllBytes(materialTexRefCfgPath) : null;
#else
            byte[] buffer = FileEx.readNewAllBytes(materialTexRefCfgPath);
#endif
            if (buffer != null)
            {
                MemoryStream ms = new MemoryStream();
                ms.Write(buffer, 0, buffer.Length);
                ms.Position = 0;
                object obj = B2InputStream.readObject(ms);
                if (obj != null)
                {
                    ret = obj as Hashtable;
                }
            }
            ret = ret == null ? new Hashtable() : ret;
            return(ret);
        }
Example #8
0
 // 取得"priority.r"
 void onGetStreamingAssets(params object[] para)
 {
     if (para != null && para.Length > 0)
     {
         byte[] buffer = (byte[])(para[0]);
         if (buffer != null)
         {
             MemoryStream ms = new MemoryStream();
             ms.Write(buffer, 0, buffer.Length);
             ms.Position = 0;
             object obj = B2InputStream.readObject(ms);
             if (obj != null)
             {
                 Hashtable map  = (Hashtable)(obj);
                 string    path = "";
                 foreach (DictionaryEntry cell in map)
                 {
                     try
                     {
                         path = CLPathCfg.persistentDataPath + "/" + cell.Key;
                         Directory.CreateDirectory(Path.GetDirectoryName(path));
                         File.WriteAllBytes(path, (byte[])(cell.Value));
                     }
                     catch (System.Exception e)
                     {
                         Debug.LogError(e);
                     }
                 }
                 // 处理完包的资源释放,弄个标志
                 Directory.CreateDirectory(Path.GetDirectoryName(hadPoc));
                 File.WriteAllText(hadPoc, "ok");
             }
         }
     }
     Utl.doCallback(onFinisInitStreaming);
 }