private async Task WriteBufferToStreamAsync()

in src/Elastic.Ingest.Apm/ApmChannel.cs [86:105]


	private async Task WriteBufferToStreamAsync(IReadOnlyCollection<IIntakeObject> b, Stream stream, CancellationToken ctx)
	{
		await WriteStanzaToStreamAsync(stream, ctx).ConfigureAwait(false);
		foreach (var @event in b)
		{
			if (@event == null) continue;

			var type = @event switch
			{
				Transaction _ => "transaction",
				_ => "unknown"
			};
			var dictionary = new Dictionary<string, object>() { { type, @event } };

			await JsonSerializer.SerializeAsync(stream, dictionary, dictionary.GetType(), ApmChannelStatics.SerializerOptions, ctx)
				.ConfigureAwait(false);

			await stream.WriteAsync(ApmChannelStatics.LineFeed, 0, 1, ctx).ConfigureAwait(false);
		}
	}