Closed
Description
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 to WriteRawValue
. In our use case we already have a ReadOnlySequence<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:
if (result.RawSerializedData.IsSingleSegment)
{
writer.WriteRawValue(result.RawSerializedData.First.Span, skipInputValidation: true);
}
else
{
writer.WriteRawValue(result.RawSerializedData.ToArray(), skipInputValidation: true);
}
API Proposal
namespace System.Text.Json
{
public sealed partial class Utf8JsonWriter
{
+ public void WriteRawValue(ReadOnlySequence<byte> json, bool skipInputValidation = false);
+ public void WriteRawValue(ReadOnlySequence<char> json, bool skipInputValidation = false);
}
}
API Usage
void MyFunc(Utf8JsonWriter writer, ReadOnlySequence<byte> sequence)
{
writer.WriteRawValue(sequence);
}
Alternative Designs
No response
Risks
No response