Files
jellyfin/src/Jellyfin.Extensions/Json/Utf8JsonExtensions.cs
Niels van Velzen 407cf5d0bf Add MediaStreamProtocol enum (#10153)
* Add MediaStreamProtocol enum

* Add default handling for enum during deserialization

---------

Co-authored-by: Cody Robibero <cody@robibe.ro>
2024-03-04 16:44:54 -07:00

28 lines
983 B
C#

using System.Text.Json;
namespace Jellyfin.Extensions.Json;
/// <summary>
/// Extensions for Utf8JsonReader and Utf8JsonWriter.
/// </summary>
public static class Utf8JsonExtensions
{
/// <summary>
/// Determines if the reader contains an empty string.
/// </summary>
/// <param name="reader">The reader.</param>
/// <returns>Whether the reader contains an empty string.</returns>
public static bool IsEmptyString(this Utf8JsonReader reader)
=> reader.TokenType == JsonTokenType.String
&& ((reader.HasValueSequence && reader.ValueSequence.IsEmpty)
|| (!reader.HasValueSequence && reader.ValueSpan.IsEmpty));
/// <summary>
/// Determines if the reader contains a null value.
/// </summary>
/// <param name="reader">The reader.</param>
/// <returns>Whether the reader contains null.</returns>
public static bool IsNull(this Utf8JsonReader reader)
=> reader.TokenType == JsonTokenType.Null;
}