コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
ファイル: NumEx.cs プロジェクト: takaaptech/Islands-World
        public static byte[] int2Bio(int v)
        {
            MemoryStream ms = null;

            try {
                ms = msPool.borrowObject("");
                B2OutputStream.writeInt(ms, v);
                ms.SetLength(ms.Position);
                byte[] ret = ms.ToArray();
//				Debug.Log("ret.Length===" + ret.Length);
//				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]);
            }
        }