private protected async ValueTask ConsumeAsync() { await reader.ReadBlockAsync(metadataBuffer.AsMemory()).ConfigureAwait(false); metadata = new LogEntryMetadata(metadataBuffer); consumed = false; }
// slow path - consume metadata asynchronously and allocate buffer on the heap private async ValueTask ConsumeSlowAsync() { if (metadataBuffer.IsEmpty) { metadataBuffer = new(new byte[LogEntryMetadata.Size]); } await reader.ReadBlockAsync(metadataBuffer).ConfigureAwait(false); metadata = new(metadataBuffer); consumed = false; }
ValueTask IDataTransferObject.WriteToAsync <TWriter>(TWriter writer, CancellationToken token) { ValueTask result; if (consumed) { result = new ValueTask(Task.FromException(new InvalidOperationException(ExceptionMessages.ReadLogEntryTwice))); } else { consumed = true; result = reader.ReadBlockAsync(length, writer, token); } return(result); }