private async Task <bool> ConstructMessageAsync(Stream outputMessageStream) { bool dataRead = false; while (true) { var chunkHeader = await ReadDataOfSizeAsync(ChunkHeaderSize).ConfigureAwait(false); var chunkSize = PackStreamBitConverter.ToUInt16(chunkHeader); if (chunkSize == 0) //NOOP or end of message { //We have been reading data so this is the end of a message zero chunk //Or there is no data remaining after this NOOP if (dataRead || ChunkBufferRemaining <= 0) { break; } //Its a NOOP so skip it continue; } var rawChunkData = await ReadDataOfSizeAsync(chunkSize).ConfigureAwait(false); dataRead = true; outputMessageStream.Write(rawChunkData, 0, chunkSize); //Put the raw chunk data into the outputstream } return(dataRead); //Return if a message was constructed }
private int ReadChunkSize() { Array.ConstrainedCopy(_buffer, _lastReadPosition, _chunkSizeBuffer, 0, _chunkSizeBuffer.Length); _lastReadPosition += _chunkSizeBuffer.Length; return(PackStreamBitConverter.ToUInt16(_chunkSizeBuffer)); }
private int ReadChunkSize() { DataStreamBuffer.WriteInto(_chunkSizeBuffer, 0, ChunkHeaderSize); return(PackStreamBitConverter.ToUInt16(_chunkSizeBuffer)); }