/// <summary> /// This method creates a buffer chunk containing the XOR of all the /// buffer chunks passed in parameter. /// The lenght of the checksum buffer is the lenght of the larger /// buffer chunk. /// This method can be used for encoding to generate the checksum packet /// as well as for decoding to generate the missing packet /// </summary> /// <param name="bytes">array of buffer chunk</param> /// <returns>array of buffer chunk containing only one item: the XOR row by row /// of all the others buffer chunks</returns> /// <remarks> /// This method accept null entries in the array because the decoder will /// certainly place an array with a missing packet to recover. /// There is no validation done in this method in order to have it generic /// because the validation rules are different on the encoder and decoder /// </remarks> private void XORData(BufferChunk xorData, int xorDataLength) { // Keep track of the tail of the array so we don't have to look it up each time int acTail = cActiveColumns - 1; // Create the XOR checksum packet for (int row = 0; row < xorDataLength; row += 8) { // Each BufferChunk can have a different size // Virtually remove all columns that are too short to continue, this improves performance while (activeColumns[acTail].Length <= row) { acTail--; } UInt64 xorValue = 0; for (int i = 0; i <= acTail; i++) // <= because acTail has already been adjusted - 1 { // XOR operation on the current row/column xorValue ^= activeColumns[i].GetPaddedUInt64(row); } // Set the value of the checksum packet for the current row xorData.SetPaddedUInt64(row, xorValue); } }
/// <summary> /// This method creates a buffer chunk containing the XOR of all the /// buffer chunks passed in parameter. /// The lenght of the checksum buffer is the lenght of the larger /// buffer chunk. /// This method can be used for encoding to generate the checksum packet /// as well as for decoding to generate the missing packet /// </summary> /// <param name="bytes">array of buffer chunk</param> /// <returns>array of buffer chunk containing only one item: the XOR row by row /// of all the others buffer chunks</returns> /// <remarks> /// This method accept null entries in the array because the decoder will /// certainly place an array with a missing packet to recover. /// There is no validation done in this method in order to have it generic /// because the validation rules are different on the encoder and decoder /// </remarks> private void XORData(BufferChunk xorData, int xorDataLength) { // Keep track of the tail of the array so we don't have to look it up each time int acTail = cActiveColumns - 1; // Create the XOR checksum packet for(int row = 0; row < xorDataLength; row += 8) { // Each BufferChunk can have a different size // Virtually remove all columns that are too short to continue, this improves performance while(activeColumns[acTail].Length <= row) { acTail--; } UInt64 xorValue = 0; for(int i = 0; i <= acTail; i++) // <= because acTail has already been adjusted - 1 { // XOR operation on the current row/column xorValue ^= activeColumns[i].GetPaddedUInt64(row); } // Set the value of the checksum packet for the current row xorData.SetPaddedUInt64(row, xorValue); } }