private async Task WriteOutOfFrameByteCoreAsync(byte value, CancellationToken cancellationToken)
{
this.AssertNotDisposed();
if (value == Frame.BeginOfFrame)
{
var message = string.Format(
CultureInfo.InvariantCulture, "A value not equal to {0:X2} is required.", Frame.BeginOfFrame);
throw new ArgumentException(message, nameof(value));
}
if ((this.stream == null) || !this.stream.CanWrite)
{
await this.writeBuffer.ReserveAsync(1, cancellationToken);
this.writeBuffer[this.writeBuffer.Count++] = value;
await this.writeBuffer.FlushAsync(cancellationToken);
}
else
{
await this.stream.WriteOutOfFrameByteAsync(value, cancellationToken);
}
}