Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SseFormatter #109832

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

eiriktsarpalis
Copy link
Member

Fix #109294.

Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

1 similar comment
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

public static partial class SseFormatter
{
public static System.Threading.Tasks.Task WriteAsync(System.Collections.Generic.IAsyncEnumerable<System.Net.ServerSentEvents.SseItem<string>> source, System.IO.Stream destination, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public static System.Threading.Tasks.Task WriteAsync<T>(System.Collections.Generic.IAsyncEnumerable<System.Net.ServerSentEvents.SseItem<T>> source, System.IO.Stream destination, System.Action<System.Buffers.IBufferWriter<byte>, System.Net.ServerSentEvents.SseItem<T>> itemFormatter, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ordering of IBufferWriter then SseItem looks wrong to me. We generally do source and then destination; the source here is the SseItem and the destination is the IBufferWriter.

Copy link
Member Author

@eiriktsarpalis eiriktsarpalis Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking of how serializers typically order their parameters, e.g. JsonConverter.Write accepts writer first and value second.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that we intentionally flipped the order in the callback to be (source, destiantion).

Notably, your PR here does not match what was approved.

Copy link
Member Author

@eiriktsarpalis eiriktsarpalis Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Notably, your PR here does not match what was approved.

Yep, this is exploring possible amendments in the callback. Another one is passing the wrapping SseItem<T> instead of just T. Will notify fxdc once we're settled on the shape.

Copy link
Member Author

@eiriktsarpalis eiriktsarpalis Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that we intentionally flipped the order in the callback to be (source, destiantion).

While technically the value is the source and the writer is the destination, this ordering is not what we commonly use in the context of serialization. For example:

Given that the delegate does represent a serialization callback, I would suggest we use the order as presented in this PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://youtu.be/ehUiLj2KvCg?t=5583

It started as writer first, then got flipped. There was no objection. And, wow, I hate listening to myself.

If you want to change it, you can bring it back for discussion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was hoping we could get this resolved quickly via email. If not, I will begrudgingly change this back to the order as originally approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add formatting support to System.Net.ServerSentEvents
3 participants