diff options
| author | Niels van Velzen <nielsvanvelzen@users.noreply.github.com> | 2024-03-05 00:44:54 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-04 16:44:54 -0700 |
| commit | 407cf5d0bf9d3563ae77fd34ce29ffae5af4339f (patch) | |
| tree | 2640dfb680cc4f302ec2dbeeb2a7cd9536005b80 /src/Jellyfin.Extensions/Json/Utf8JsonExtensions.cs | |
| parent | 83d2bc3f9f13c62f6d3ef16c4fe75f0f5a18110d (diff) | |
Add MediaStreamProtocol enum (#10153)
* Add MediaStreamProtocol enum
* Add default handling for enum during deserialization
---------
Co-authored-by: Cody Robibero <cody@robibe.ro>
Diffstat (limited to 'src/Jellyfin.Extensions/Json/Utf8JsonExtensions.cs')
| -rw-r--r-- | src/Jellyfin.Extensions/Json/Utf8JsonExtensions.cs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/Jellyfin.Extensions/Json/Utf8JsonExtensions.cs b/src/Jellyfin.Extensions/Json/Utf8JsonExtensions.cs new file mode 100644 index 000000000..d06508a26 --- /dev/null +++ b/src/Jellyfin.Extensions/Json/Utf8JsonExtensions.cs @@ -0,0 +1,27 @@ +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; +} |
