/// <summary> /// 对数据进行打包处理,不足一包的进行整包处理,并填充为指定数据 /// </summary> /// <param name="buffer"></param> /// <param name="packageSize"></param> /// <param name="val"></param> public static byte[][] GenFuncPackage(byte[] buffer, int packageSize, byte val = 0xFF) { byte[][] _return = null; //---计算包总数 int packageNum = buffer.Length / packageSize; //---校验整数包 if ((buffer.Length % packageSize) != 0) { packageNum += 1; } //---申请缓存空间 _return = new byte[packageNum][]; //---数据进行分包处理 for (int i = 0; i < packageNum; i++) { int length = ((buffer.Length - i * packageSize) > packageSize) ? packageSize : (buffer.Length - i * packageSize); //---数据缓存区 _return[i] = new byte[length]; //---判断是不是最后一包 if (i == (packageNum - 1)) { CGenFuncMem.GenFuncMemset(ref _return[i]); } //数据拷贝处理 Array.Copy(buffer, i * packageSize, _return[i], 0, length); } return(_return); }
/// <summary> /// /// </summary> /// <param name="buffer"></param> /// <param name="val"></param> public static void GenFuncMemset(ref int[] buffer, int val = 0xFFFF) { CGenFuncMem.GenFuncMemset(ref buffer, buffer.Length, val); }
/// <summary> /// /// </summary> /// <param name="buffer"></param> /// <param name="length"></param> /// <param name="val"></param> public static void GenFuncMemset(ref byte[] buffer, byte val = 0xFF) { CGenFuncMem.GenFuncMemset(ref buffer, buffer.Length, val); }