Example #1
0
        public static byte[] getB2Int(int v)
        {
            try {
                MemoryStream ms = msPool.borrowObject("");
                B2OutputStream.writeB2Int(ms, v);
                ms.SetLength(ms.Position);
                byte[] ret = ms.ToArray();
//				byte[] outbs = new byte[ms.Position];
//				ret.CopyTo(outbs, 0);
                msPool.returnObject(ms);
                return(ret);
            } catch (System.Exception e) {
                //Debug.LogError (e);
                return(new byte[0]);
            }
        }
Example #2
0
        public byte[] defaultPackMessage(object obj)
        {
            os.Position  = 0;
            os2.Position = 0;

            B2OutputStream.writeObject(os, obj);
            int len = (int)os.Position;

            B2OutputStream.writeInt(os2, len);
            os2.Write(os.ToArray(), 0, len);
            int pos = (int)os2.Position;

            byte[] result = new byte[pos];
            os2.Position = 0;
            os2.Read(result, 0, pos);
            return(result);
        }
Example #3
0
        /// <summary>
        /// Saves the new res.保存最新取得的资源
        /// </summary>
        /// <param name='path'>
        /// Path.
        /// </param>
        /// <param name='content'>
        /// Content.
        /// </param>
        void saveNewRes(string path, byte[] content)
        {
            string file = PStr.begin().a(CLPathCfg.persistentDataPath).a("/").a(path).end();

            Directory.CreateDirectory(Path.GetDirectoryName(file));
            File.WriteAllBytes(file, content);
            if (otherResVerNew[path] != null)
            { //优先更新资源已经是最新的了,所以不用再同步
                otherResVerOld[path] = otherResVerNew[path];
                MemoryStream ms = new MemoryStream();
                B2OutputStream.writeMap(ms, otherResVerOld);

                string vpath = PStr.begin().a(CLPathCfg.persistentDataPath).a("/").a(mVerOtherPath).end();
                Directory.CreateDirectory(Path.GetDirectoryName(vpath));
                File.WriteAllBytes(vpath, ms.ToArray());
            }
        }
Example #4
0
        /// <summary>
        /// Encodes the data.数据组包准备发送
        /// </summary>
        /// <returns>The data.</returns>
        /// <param name="obj">Object.</param>
        public virtual byte[] encodeData(object obj)
        {
            os.Position  = 0;
            os2.Position = 0;

            B2OutputStream.writeObject(os, obj);
            int len = (int)os.Position;

            B2OutputStream.writeInt(os2, len);
            os2.Write(os.ToArray(), 0, len);
            int pos = (int)os2.Position;

            byte[] result = new byte[pos];
            os2.Position = 0;
            os2.Read(result, 0, pos);
            return(result);
        }
Example #5
0
        public static byte[] Long2Bio(long v)
        {
            MemoryStream ms = null;

            try {
                ms = msPool.borrowObject("");
                B2OutputStream.writeLong(ms, v);
                ms.SetLength(ms.Position);
                byte[] ret = ms.ToArray();
//				byte[] outbs = new byte[ms.Position];
//				ret.CopyTo(outbs, 0);
                msPool.returnObject(ms);
                return(ret);
            } catch (System.Exception e) {
                //Debug.LogError (e);
                if (ms != null)
                {
                    msPool.returnObject(ms);
                }
                return(new byte[0]);
            }
        }