Exemple #1
0
        /// <summary>
        /// 将数据解析为MessagePackage对象
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static MessagePackage ResolvePack(byte[] data)
        {
            Ensure.IsNotNull(data, "data不能为空");
            Ensure.Assert(data.Length <= _headerSize, "数据长度应该大于4");

            var pack = new MessagePackage(data.Length - _headerSize);

            System.Buffer.BlockCopy(data, _headerSize, pack.Data, 0, pack.Length);

            return(pack);
        }
Exemple #2
0
        public static MessagePackage BuildPack(byte[] buffer)
        {
            Ensure.IsNotNull(buffer);

            var pack = new MessagePackage(_headerSize + buffer.Length);

            for (int i = 0; i < _headerSize; i++)
            {
                pack.Data[i] |= (byte)(buffer.Length >> i * 8);
            }

            System.Buffer.BlockCopy(buffer, 0, pack.Data, _headerSize, buffer.Length);

            return(pack);
        }