public ValueTask SerializeAsync(CborWriter writer, T value, CancellationToken cancellationToken = default) { if (value is null) { writer.WriteNull(); return(writer.FlushAsync(cancellationToken)); } var step = 0; var task = Serializer(writer, value, ref step, cancellationToken); if (task.IsCompletedSuccessfully && step == MaxSteps) // if everything is synchronous, we should not hit any async path at all { return(writer.FlushAsync(cancellationToken)); } return(AwaitSerializeAsync(task, writer, value, step, cancellationToken)); }
private static async Task FillPipeAsync(PipeWriter writer) { CborWriter cborWriter = new CborWriter(writer); var document = new Document { Key = "Hello", Value = "World" }; var formatter = new ComplexClassFormatter <Document>(); await formatter.SerializeAsync(cborWriter, document).ConfigureAwait(false); //await cborWriter.WriteMap(input).ConfigureAwait(false); await cborWriter.FlushAsync().ConfigureAwait(false); await writer.CompleteAsync().ConfigureAwait(false); }