/// <summary> /// Asynchronous handler for traversing a DICOM element. /// </summary> /// <param name="element">Element to traverse.</param> /// <returns>true if traversing completed without issues, false otherwise.</returns> public async Task <bool> OnElementAsync(DicomElement element) { WriteTagHeader(element.Tag, element.ValueRepresentation, element.Length); IByteBuffer buffer = element.Buffer; if (buffer is EndianByteBuffer) { EndianByteBuffer ebb = buffer as EndianByteBuffer; if (ebb.Endian != Endian.LocalMachine && ebb.Endian == _target.Endian) { buffer = ebb.Internal; } } else if (_target.Endian != Endian.LocalMachine) { if (element.ValueRepresentation.UnitSize > 1) { buffer = new SwapByteBuffer(buffer, element.ValueRepresentation.UnitSize); } } if (element.Length < this._options.LargeObjectSize) { _target.Write(buffer.Data, 0, buffer.Size); } else { await _target.WriteAsync(buffer.Data, 0, buffer.Size).ConfigureAwait(false); } return(true); }
private static async Task WriteBufferAsync(IByteTarget target, IByteBuffer buffer, uint largeObjectSize) { var offset = 0; var remainingSize = buffer.Size; while (remainingSize > largeObjectSize) { var range = buffer.GetByteRange(offset, (int)largeObjectSize); await target.WriteAsync(range, 0, largeObjectSize).ConfigureAwait(false); offset += (int)largeObjectSize; remainingSize -= largeObjectSize; } await target.WriteAsync(buffer.GetByteRange(offset, (int)remainingSize), 0, (uint)remainingSize).ConfigureAwait(false); }
/// <summary> /// Write DICOM file preamble. /// </summary> /// <param name="target">Byte target subject to writing.</param> private static Task WritePreambleAsync(IByteTarget target) { var preamble = new byte[132]; preamble[128] = (byte)'D'; preamble[129] = (byte)'I'; preamble[130] = (byte)'C'; preamble[131] = (byte)'M'; return(target.WriteAsync(preamble, 0, 132)); }
/// <summary> /// Write DICOM file preamble. /// </summary> /// <param name="target">Byte target subject to writing.</param> private static Task WritePreambleAsync(IByteTarget target) { var preamble = new byte[132]; preamble[128] = (byte)'D'; preamble[129] = (byte)'I'; preamble[130] = (byte)'C'; preamble[131] = (byte)'M'; return target.WriteAsync(preamble, 0, 132); }