internal void WritePropertyName(DateTimeOffset value) { Span <byte> buffer = stackalloc byte[JsonConstants.MaximumFormatDateTimeOffsetLength]; JsonWriterHelper.WriteDateTimeOffsetTrimmed(buffer, value, out int bytesWritten); WritePropertyNameUnescaped(buffer.Slice(0, bytesWritten)); }
private void WriteStringMinimized(ReadOnlySpan <byte> escapedPropertyName, DateTimeOffset value) { Debug.Assert(escapedPropertyName.Length < int.MaxValue - JsonConstants.MaximumFormatDateTimeOffsetLength - 6); int minRequired = escapedPropertyName.Length + JsonConstants.MaximumFormatDateTimeOffsetLength + 5; // 2 quotes for property name, 2 quotes for date, and 1 colon int maxRequired = minRequired + 1; // Optionally, 1 list separator if (_memory.Length - BytesPending < maxRequired) { Grow(maxRequired); } Span <byte> output = _memory.Span; if (_currentDepth < 0) { output[BytesPending++] = JsonConstants.ListSeparator; } output[BytesPending++] = JsonConstants.Quote; escapedPropertyName.CopyTo(output.Slice(BytesPending)); BytesPending += escapedPropertyName.Length; output[BytesPending++] = JsonConstants.Quote; output[BytesPending++] = JsonConstants.KeyValueSeperator; output[BytesPending++] = JsonConstants.Quote; JsonWriterHelper.WriteDateTimeOffsetTrimmed(output.Slice(BytesPending), value, out int bytesWritten); BytesPending += bytesWritten; output[BytesPending++] = JsonConstants.Quote; }
private void WriteStringMinimized(ReadOnlySpan <char> escapedPropertyName, DateTimeOffset value) { Debug.Assert(escapedPropertyName.Length < (int.MaxValue / JsonConstants.MaxExpansionFactorWhileTranscoding) - JsonConstants.MaximumFormatDateTimeOffsetLength - 6); // All ASCII, 2 quotes for property name, 2 quotes for date, and 1 colon => escapedPropertyName.Length + JsonConstants.MaximumFormatDateTimeOffsetLength + 5 // Optionally, 1 list separator, and up to 3x growth when transcoding int maxRequired = (escapedPropertyName.Length * JsonConstants.MaxExpansionFactorWhileTranscoding) + JsonConstants.MaximumFormatDateTimeOffsetLength + 6; if (_memory.Length - BytesPending < maxRequired) { Grow(maxRequired); } Span <byte> output = _memory.Span; if (_currentDepth < 0) { output[BytesPending++] = JsonConstants.ListSeparator; } output[BytesPending++] = JsonConstants.Quote; TranscodeAndWrite(escapedPropertyName, output); output[BytesPending++] = JsonConstants.Quote; output[BytesPending++] = JsonConstants.KeyValueSeperator; output[BytesPending++] = JsonConstants.Quote; JsonWriterHelper.WriteDateTimeOffsetTrimmed(output.Slice(BytesPending), value, out int bytesWritten); BytesPending += bytesWritten; output[BytesPending++] = JsonConstants.Quote; }
public static string FormatDateTimeOffset(DateTimeOffset value) { Span <byte> span = stackalloc byte[JsonConstants.MaximumFormatDateTimeOffsetLength]; JsonWriterHelper.WriteDateTimeOffsetTrimmed(span, value, out int bytesWritten); return(JsonReaderHelper.GetTextFromUtf8(span.Slice(0, bytesWritten))); }
private void WriteStringIndented(ReadOnlySpan <byte> escapedPropertyName, DateTimeOffset value) { int indent = Indentation; Debug.Assert(indent <= 2 * _options.MaxDepth); Debug.Assert(escapedPropertyName.Length < int.MaxValue - indent - JsonConstants.MaximumFormatDateTimeOffsetLength - 7 - s_newLineLength); int minRequired = indent + escapedPropertyName.Length + JsonConstants.MaximumFormatDateTimeOffsetLength + 6; // 2 quotes for property name, 2 quotes for date, 1 colon, and 1 space int maxRequired = minRequired + 1 + s_newLineLength; // Optionally, 1 list separator and 1-2 bytes for new line if (_memory.Length - BytesPending < maxRequired) { Grow(maxRequired); } Span <byte> output = _memory.Span; if (_currentDepth < 0) { output[BytesPending++] = JsonConstants.ListSeparator; } Debug.Assert(_options.SkipValidation || _tokenType != JsonTokenType.PropertyName); if (_tokenType != JsonTokenType.None) { WriteNewLine(output); } JsonWriterHelper.WriteIndentation(output.Slice(BytesPending), indent); BytesPending += indent; output[BytesPending++] = JsonConstants.Quote; escapedPropertyName.CopyTo(output.Slice(BytesPending)); BytesPending += escapedPropertyName.Length; output[BytesPending++] = JsonConstants.Quote; output[BytesPending++] = JsonConstants.KeyValueSeperator; output[BytesPending++] = JsonConstants.Space; output[BytesPending++] = JsonConstants.Quote; JsonWriterHelper.WriteDateTimeOffsetTrimmed(output.Slice(BytesPending), value, out int bytesWritten); BytesPending += bytesWritten; output[BytesPending++] = JsonConstants.Quote; }
private void WriteStringIndented(ReadOnlySpan <char> escapedPropertyName, DateTimeOffset value) { int indent = Indentation; Debug.Assert(indent <= 2 * _options.MaxDepth); Debug.Assert(escapedPropertyName.Length < (int.MaxValue / JsonConstants.MaxExpansionFactorWhileTranscoding) - indent - JsonConstants.MaximumFormatDateTimeOffsetLength - 7 - s_newLineLength); // All ASCII, 2 quotes for property name, 2 quotes for date, 1 colon, and 1 space => escapedPropertyName.Length + JsonConstants.MaximumFormatDateTimeOffsetLength + 6 // Optionally, 1 list separator, 1-2 bytes for new line, and up to 3x growth when transcoding int maxRequired = indent + (escapedPropertyName.Length * JsonConstants.MaxExpansionFactorWhileTranscoding) + JsonConstants.MaximumFormatDateTimeOffsetLength + 7 + s_newLineLength; if (_memory.Length - BytesPending < maxRequired) { Grow(maxRequired); } Span <byte> output = _memory.Span; if (_currentDepth < 0) { output[BytesPending++] = JsonConstants.ListSeparator; } Debug.Assert(_options.SkipValidation || _tokenType != JsonTokenType.PropertyName); if (_tokenType != JsonTokenType.None) { WriteNewLine(output); } JsonWriterHelper.WriteIndentation(output.Slice(BytesPending), indent); BytesPending += indent; output[BytesPending++] = JsonConstants.Quote; TranscodeAndWrite(escapedPropertyName, output); output[BytesPending++] = JsonConstants.Quote; output[BytesPending++] = JsonConstants.KeyValueSeperator; output[BytesPending++] = JsonConstants.Space; output[BytesPending++] = JsonConstants.Quote; JsonWriterHelper.WriteDateTimeOffsetTrimmed(output.Slice(BytesPending), value, out int bytesWritten); BytesPending += bytesWritten; output[BytesPending++] = JsonConstants.Quote; }
private void WriteStringValueIndented(DateTimeOffset value) { int indent = Indentation; Debug.Assert(indent <= 2 * JsonConstants.MaxWriterDepth); // 2 quotes, and optionally, 1 list separator and 1-2 bytes for new line int maxRequired = indent + JsonConstants.MaximumFormatDateTimeOffsetLength + 3 + s_newLineLength; if (_memory.Length - BytesPending < maxRequired) { Grow(maxRequired); } Span <byte> output = _memory.Span; if (_currentDepth < 0) { output[BytesPending++] = JsonConstants.ListSeparator; } if (_tokenType != JsonTokenType.PropertyName) { if (_tokenType != JsonTokenType.None) { WriteNewLine(output); } JsonWriterHelper.WriteIndentation(output.Slice(BytesPending), indent); BytesPending += indent; } output[BytesPending++] = JsonConstants.Quote; JsonWriterHelper.WriteDateTimeOffsetTrimmed(output.Slice(BytesPending), value, out int bytesWritten); BytesPending += bytesWritten; output[BytesPending++] = JsonConstants.Quote; }
private void WriteStringValueMinimized(DateTimeOffset value) { int maxRequired = JsonConstants.MaximumFormatDateTimeOffsetLength + 3; // 2 quotes, and optionally, 1 list separator if (_memory.Length - BytesPending < maxRequired) { Grow(maxRequired); } Span <byte> output = _memory.Span; if (_currentDepth < 0) { output[BytesPending++] = JsonConstants.ListSeparator; } output[BytesPending++] = JsonConstants.Quote; JsonWriterHelper.WriteDateTimeOffsetTrimmed(output.Slice(BytesPending), value, out int bytesWritten); BytesPending += bytesWritten; output[BytesPending++] = JsonConstants.Quote; }