-
Notifications
You must be signed in to change notification settings - Fork 4.9k
[API Proposal]: Add ReadOnlySequence overload for WriteRawValue #68223
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis Issue DetailsBackground and motivationWhen using the But because the API only accepts string or span, we need to write the following: if (result.RawSerializedData.IsSingleSegment)
{
writer.WriteRawValue(result.RawSerializedData.First.Span, skipInputValidation: true);
}
else
{
writer.WriteRawValue(result.RawSerializedData.ToArray(), skipInputValidation: true);
} API Proposalnamespace System.Text.Json
{
public sealed partial class Utf8JsonWriter
{
+ public void WriteRawValue(ReadOnlySequence<byte> json, bool skipInputValidation = false);
+ public void WriteRawValue([StringSyntax(StringSyntaxAttribute.Json)] ReadOnlySequence<char> json, bool skipInputValidation = false);
}
} API Usagevoid MyFunc(Utf8JsonWriter writer, ReadOnlySequence<byte> sequence)
{
writer.WriteRawValue(sequence);
} Alternative DesignsNo response RisksNo response
|
There isn't an implicit conversion from a string to a |
Haha, I was too focused on filling out the API template! |
Suggestion looks good to me as proposed, although we unlikely will have time to do it in this release, marking as 8.0.0 so it's on our radar for vNext. |
namespace System.Text.Json;
public sealed partial class Utf8JsonWriter
{
public void WriteRawValue(ReadOnlySequence<byte> json, bool skipInputValidation = false);
} |
Hi, I would try to add this API by this PR, could you please review? Also, I modified parameter name from
|
Change sounds reasonable to me, thanks for correcting it. |
Background and motivation
When using the
Utf8JsonWriter.WriteRawValue
API, you can't pass multiple segments in to write a single value, you have to allocate a contiguous array and do a single call toWriteRawValue
. In our use case we already have aReadOnlySequence<byte>
and want to write it as a raw json value.But because the API only accepts string or span, we need to write the following:
API Proposal
API Usage
Alternative Designs
No response
Risks
No response
The text was updated successfully, but these errors were encountered: