private List <byte[]> GetChunkedFrame(uint chunkSize, DataFrame dataFrame) { byte[] rawData; using (MemoryStream stream = new MemoryStream()) { dataFrame.EncodeChunk(stream); rawData = stream.ToArray(); } List <byte[]> rawChunks = new List <byte[]>(); if (chunkSize == 0) { using (MemoryStream completeOutputStream = new MemoryStream()) { dataFrame.NetworkMessageHeader.Encode(completeOutputStream); dataFrame.PayloadHeader.Encode(completeOutputStream); completeOutputStream.Write(rawData, 0, rawData.Length); rawChunks.Add(completeOutputStream.ToArray()); } } else { for (uint i = 0; i < rawData.LongLength; i += chunkSize) { NetworkMessageHeader networkHeader = GetChunkedNetworkHeader(); ChunkedMessage chunkedMessage = new ChunkedMessage(); chunkedMessage.PayloadHeader = new ChunkedPayloadHeader(); chunkedMessage.PayloadHeader.DataSetWriterID = dataFrame.PayloadHeader.DataSetWriterID[0]; chunkedMessage.NetworkMessageHeader = networkHeader; chunkedMessage.TotalSize = (uint)rawData.LongLength; chunkedMessage.ChunkOffset = i; chunkedMessage.MessageSequenceNumber = dataFrame.DataSetMessageSequenceNumber; // Check if can copy a "full" chunk or just the remaining elements of the array. long length = Math.Min(chunkSize, rawData.LongLength - chunkedMessage.ChunkOffset); chunkedMessage.ChunkData = new byte[length]; Array.Copy(rawData, i, chunkedMessage.ChunkData, 0, length); using (MemoryStream stream = new MemoryStream()) { chunkedMessage.Encode(stream); rawChunks.Add(stream.ToArray()); } } } return(rawChunks); }
public List <byte[]> GetChunkedMetaFrame(uint chunkSize, EncodingOptions options, ushort sequenceNumber) { byte[] rawMessage = GetEncodedMetaFrame(options, sequenceNumber, false); List <byte[]> rawChunks = new List <byte[]>(); if (chunkSize == 0) { using (MemoryStream completeOutputStream = new MemoryStream()) { m_MetaFrame.NetworkMessageHeader.Encode(completeOutputStream); completeOutputStream.Write(rawMessage, 0, rawMessage.Length); rawChunks.Add(completeOutputStream.ToArray()); } } else { for (uint i = 0; i < rawMessage.LongLength; i += chunkSize) { NetworkMessageHeader networkHeader = GetChunkedNetworkHeader(true); ChunkedMessage chunkedMessage = new ChunkedMessage(); chunkedMessage.PayloadHeader = new ChunkedPayloadHeader(); //chunkedMessage.PayloadHeader.DataSetWriterID = m_MetaFrame.DataSetWriterID; chunkedMessage.NetworkMessageHeader = networkHeader; chunkedMessage.TotalSize = (uint)rawMessage.LongLength; chunkedMessage.ChunkOffset = i; chunkedMessage.MessageSequenceNumber = m_MetaFrame.SequenceNumber; // Check if can copy a "full" chunk or just the remaining elements of the array. long length = Math.Min(chunkSize, rawMessage.LongLength - chunkedMessage.ChunkOffset); chunkedMessage.ChunkData = new byte[length]; Array.Copy(rawMessage, i, chunkedMessage.ChunkData, 0, length); using (MemoryStream stream = new MemoryStream()) { chunkedMessage.Encode(stream); rawChunks.Add(stream.ToArray()); } } } return(rawChunks); }
public virtual List <byte[]> GetChunkedMetaFrame(uint chunkSize) { if (m_MetaFrame == null || chunkSize == 0) { return(null); } byte[] rawMessage = null; using (MemoryStream outputStream = new MemoryStream()) { m_MetaFrame.EncodeChunk(outputStream); rawMessage = outputStream.ToArray(); } List <byte[]> rawChunks = new List <byte[]>(); for (uint i = 0; i < rawMessage.LongLength; i += chunkSize) { NetworkMessageHeader networkHeader = GetChunkedMetaNetworkHeader(); ChunkedMessage chunkedMessage = new ChunkedMessage(); chunkedMessage.PayloadHeader = new ChunkedPayloadHeader(); //chunkedMessage.PayloadHeader.DataSetWriterID = m_MetaFrame.DataSetWriterID; chunkedMessage.NetworkMessageHeader = networkHeader; chunkedMessage.TotalSize = (uint)rawMessage.LongLength; chunkedMessage.ChunkOffset = i; chunkedMessage.MessageSequenceNumber = m_MetaFrame.SequenceNumber; // Check if can copy a "full" chunk or just the remaining elements of the array. long length = Math.Min(chunkSize, rawMessage.LongLength - chunkedMessage.ChunkOffset); chunkedMessage.ChunkData = new byte[length]; Array.Copy(rawMessage, i, chunkedMessage.ChunkData, 0, length); using (MemoryStream stream = new MemoryStream()) { chunkedMessage.Encode(stream); rawChunks.Add(stream.ToArray()); } } return(rawChunks); }