Example #1
0
        /// <summary>
        /// Method to convert a byte Array into Eigh tByte Chunks
        /// </summary>
        /// <param name="data">Byte array that contains data to convert</param>
        /// <returns>List containing EightByteChunks</returns>
        public static List <EightByteChunk> ArrayToEightByteChunks(Array data)
        {
            //If no data exists return null
            if (data.Length == 0)
            {
                return(null);
            }

            // Used to get the length of the data
            EightByteChunk byteChunkData       = new EightByteChunk();
            int            lengthByteChunkData = byteChunkData.OtherParameters.Length;

            // Calculate the size if not on the byte boundary then all 1 to make it so
            int maxSize = System.Convert.ToInt32(Math.Ceiling((double)data.Length / (double)lengthByteChunkData)); //PES09182009 Modified so it would also work on Mobile

            // Create buffer to hold the data passed in from the array
            byte[] chunkBuffer = new byte[maxSize * lengthByteChunkData];

            // Copy data to the buffer created above
            Buffer.BlockCopy(data, 0, chunkBuffer, 0, data.Length);

            List <EightByteChunk> byteChunkList = new List <EightByteChunk>();

            // Iterate over the buffer and grab the appropriate number of bytes, store into the List
            for (int i = 0; i < maxSize; i++)
            {
                byteChunkData = new EightByteChunk();
                Buffer.BlockCopy(chunkBuffer, i * lengthByteChunkData, byteChunkData.OtherParameters, 0, lengthByteChunkData);

                byteChunkList.Add(byteChunkData);
            }

            return(byteChunkList);
        }
Example #2
0
        /// <summary>
        /// Method to convert Eight Byte Chunks into an Array
        /// </summary>
        /// <param name="chunkList">List that holds the EightByteChunks</param>
        /// <returns>Byte array</returns>
        public static Array EightByteChunksToArray(List <EightByteChunk> chunkList)
        {
            EightByteChunk byteChunkData       = new EightByteChunk();
            int            lengthByteChunkData = byteChunkData.OtherParameters.Length;

            //Data passed in does not exist.
            if (chunkList.Count == 0)
            {
                return(null);
            }

            // Create the appropriate sized buffer for this type
            byte[] chunkBuffer = new byte[chunkList.Count * lengthByteChunkData];

            // Go through each item and append to the buffer
            for (int i = 0; i < chunkList.Count; i++)
            {
                Buffer.BlockCopy(chunkList[i].OtherParameters, 0, chunkBuffer, i * lengthByteChunkData, lengthByteChunkData);
            }

            return((Array)chunkBuffer);
        }