BufferConsumer<T>
public struct BufferConsumer<T> : IReadOnlySpanConsumer<T>, ISupplier<ReadOnlyMemory<T>, CancellationToken, ValueTask>, IFunctional<Func<ReadOnlyMemory<T>, CancellationToken, ValueTask>>, IEquatable<BufferConsumer<T>>
Represents implementation of IReadOnlySpanConsumer<T>
in the form of the writer to IBufferWriter<T>.
using DotNext.Runtime.CompilerServices;
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace DotNext.Buffers
{
[StructLayout(LayoutKind.Auto)]
public readonly struct BufferConsumer<[System.Runtime.CompilerServices.Nullable(2)] T> : IReadOnlySpanConsumer<T>, ISupplier<ReadOnlyMemory<T>, CancellationToken, ValueTask>, IFunctional<Func<ReadOnlyMemory<T>, CancellationToken, ValueTask>>, IEquatable<BufferConsumer<T>>
{
private readonly IBufferWriter<T> output;
public bool IsEmpty => output == null;
[System.Runtime.CompilerServices.NullableContext(1)]
public BufferConsumer(IBufferWriter<T> output)
{
if (output == null)
throw new ArgumentNullException("output");
this.output = output;
}
void IReadOnlySpanConsumer<T>.Invoke(ReadOnlySpan<T> span)
{
BuffersExtensions.Write<T>(output, span);
}
ValueTask ISupplier<ReadOnlyMemory<T>, CancellationToken, ValueTask>.Invoke(ReadOnlyMemory<T> input, CancellationToken token)
{
if (!token.IsCancellationRequested) {
ValueTask result = default(ValueTask);
try {
BuffersExtensions.Write<T>(output, input.Span);
return result;
} catch (Exception exception) {
return ValueTask.FromException(exception);
}
}
return ValueTask.FromCanceled(token);
}
[System.Runtime.CompilerServices.NullableContext(2)]
public override string ToString()
{
return output?.ToString();
}
[CompilerGenerated]
private bool PrintMembers(StringBuilder builder)
{
builder.Append("IsEmpty = ");
builder.Append(IsEmpty.ToString());
return true;
}
public static bool operator !=(BufferConsumer<T> left, BufferConsumer<T> right)
{
return !(left == right);
}
public static bool operator ==(BufferConsumer<T> left, BufferConsumer<T> right)
{
return left.Equals(right);
}
[CompilerGenerated]
public override int GetHashCode()
{
return EqualityComparer<IBufferWriter<T>>.Default.GetHashCode(output);
}
[CompilerGenerated]
public override bool Equals(object obj)
{
if (obj is BufferConsumer<T>)
return Equals((BufferConsumer<T>)obj);
return false;
}
[CompilerGenerated]
public bool Equals(BufferConsumer<T> other)
{
return EqualityComparer<IBufferWriter<T>>.Default.Equals(output, other.output);
}
}
}