Ejemplo n.º 1
0
        private void AppendString(Span <byte> output, string value, ValuePresenterLimits limits, out int byteCount)
        {
            if (value.Length > limits.MaxValueLength)
            {
                byteCount = limits.MaxValueLength - 1;
                CharBreakingUtf8Encoder.Encode(value.AsSpan().Slice(0, byteCount), output);
                byteCount += AppendEllipsis(output, byteCount);
                return;
            }

            byteCount = Encoding.UTF8.GetBytes(value, output);
        }
Ejemplo n.º 2
0
        // Does NOT have to be thread-safe
        private void WriteNameToWriter(Utf8JsonWriter writer, string name)
        {
            if (name.Length > Limits.MaxNameLength)
            {
                CharBreakingUtf8Encoder.Encode(name, _truncatedNameBytes);
                Utf8Ellipsis.CopyTo(_truncatedNameBytes.AsSpan().Slice(Limits.MaxNameLength - 1));
                writer.WriteStringValue(_truncatedNameBytes);
                return;
            }

            writer.WriteStringValue(name);
        }