// // Licensed under the MIT License. See LICENSE file in the project root for full license information. // namespace MUnique.OpenMU.Network; using System.Diagnostics.Metrics; using System.IO.Pipelines; using System.Threading; /// /// A wrapper for an existing , which has metrics about the written bytes. /// public class ExtendedPipeWriter : PipeWriter { private readonly PipeWriter _target; private readonly Counter _writeCounter; /// /// Initializes a new instance of the class. /// /// The target . /// A counter for the written bytes. public ExtendedPipeWriter(PipeWriter target, Counter writeCounter) { this._target = target; this._writeCounter = writeCounter; } /// public override void Complete(Exception? exception = null) { this._target.Complete(exception); } /// public override void CancelPendingFlush() { this._target.CancelPendingFlush(); } /// public override ValueTask FlushAsync(CancellationToken cancellationToken = default) { return this._target.FlushAsync(cancellationToken); } /// public override void Advance(int bytes) { this._target.Advance(bytes); this._writeCounter.Add(bytes); } /// public override Memory GetMemory(int sizeHint = 0) { return this._target.GetMemory(sizeHint); } /// public override Span GetSpan(int sizeHint = 0) { var span = this._target.GetSpan(sizeHint); span.Clear(); return span; } }