📄 lib/src/Internal/AsciiText.cs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
using System;
using System.Text;

namespace SharpDlt.Internal;

/// <summary>Helpers to decode the fixed size ASCII fields of the DLT protocol.</summary>
internal static class AsciiText
{
    /// <summary>
    /// Decodes a fixed size ASCII field, replacing invalid bytes and stripping NUL padding.
    /// </summary>
    public static string Decode(ReadOnlySpan<byte> data) =>
        Encoding.ASCII.GetString(data).Replace("\0", string.Empty, StringComparison.Ordinal);
}