diff options
Diffstat (limited to 'lib/Utils/src')
-rw-r--r-- | lib/Utils/src/Extensions/JsonExtensions.cs | 27 | ||||
-rw-r--r-- | lib/Utils/src/VnEncoding.cs | 64 |
2 files changed, 3 insertions, 88 deletions
diff --git a/lib/Utils/src/Extensions/JsonExtensions.cs b/lib/Utils/src/Extensions/JsonExtensions.cs index 523f772..55ad958 100644 --- a/lib/Utils/src/Extensions/JsonExtensions.cs +++ b/lib/Utils/src/Extensions/JsonExtensions.cs @@ -1,5 +1,5 @@ /* -* Copyright (c) 2022 Vaughn Nugent +* Copyright (c) 2023 Vaughn Nugent * * Library: VNLib * Package: VNLib.Utils @@ -64,19 +64,6 @@ namespace VNLib.Utils.Extensions public static class JsonExtensions { /// <summary> - /// Converts a JSON encoded string to an object of the specified type - /// </summary> - /// <typeparam name="T">Output type of the object</typeparam> - /// <param name="value"></param> - /// <param name="options"><see cref="JsonSerializerOptions"/> to use during de-serialization</param> - /// <returns>The new object or default if the string is null or empty</returns> - /// <exception cref="JsonException"></exception> - /// <exception cref="NotSupportedException"></exception> - public static T? AsJsonObject<T>(this string value, JsonSerializerOptions? options = null) - { - return !string.IsNullOrWhiteSpace(value) ? JsonSerializer.Deserialize<T>(value, options) : default; - } - /// <summary> /// Converts a JSON encoded binary data to an object of the specified type /// </summary> /// <typeparam name="T">Output type of the object</typeparam> @@ -159,18 +146,6 @@ namespace VNLib.Utils.Extensions } /// <summary> - /// Attemts to serialze an object to a JSON encoded string - /// </summary> - /// <param name="obj"></param> - /// <param name="options"><see cref="JsonSerializerOptions"/> to use during serialization</param> - /// <returns>A JSON encoded string of the serialized object, or null if the object is null</returns> - /// <exception cref="NotSupportedException"></exception> - public static string? ToJsonString<T>(this T obj, JsonSerializerOptions? options = null) - { - return obj == null ? null : JsonSerializer.Serialize(obj, options); - } - - /// <summary> /// Merges the current <see cref="JsonDocument"/> with another <see cref="JsonDocument"/> to /// create a new document of combined properties /// </summary> diff --git a/lib/Utils/src/VnEncoding.cs b/lib/Utils/src/VnEncoding.cs index 89863aa..c9cdbb0 100644 --- a/lib/Utils/src/VnEncoding.cs +++ b/lib/Utils/src/VnEncoding.cs @@ -74,67 +74,7 @@ namespace VNLib.Utils throw; } } - - /// <summary> - /// Attempts to deserialze a json object from a stream of UTF8 data - /// </summary> - /// <typeparam name="T">The type of the object to deserialize</typeparam> - /// <param name="data">Binary data to read from</param> - /// <param name="options"><see cref="JsonSerializerOptions"/> object to pass to deserializer</param> - /// <returns>The object decoded from the stream</returns> - /// <exception cref="JsonException"></exception> - /// <exception cref="NotSupportedException"></exception> - public static T? JSONDeserializeFromBinary<T>(Stream? data, JsonSerializerOptions? options = null) - { - //Return default if null - if (data == null) - { - return default; - } - //Create a memory stream as a buffer - using VnMemoryStream ms = new(); - //Copy stream data to memory - data.CopyTo(ms, null); - if (ms.Length > 0) - { - //Rewind - ms.Position = 0; - //Recover data from stream - return ms.AsSpan().AsJsonObject<T>(options); - } - //Stream is empty - return default; - } - /// <summary> - /// Attempts to deserialze a json object from a stream of UTF8 data - /// </summary> - /// <param name="data">Binary data to read from</param> - /// <param name="type"></param> - /// <param name="options"><see cref="JsonSerializerOptions"/> object to pass to deserializer</param> - /// <returns>The object decoded from the stream</returns> - /// <exception cref="JsonException"></exception> - /// <exception cref="NotSupportedException"></exception> - public static object? JSONDeserializeFromBinary(Stream? data, Type type, JsonSerializerOptions? options = null) - { - //Return default if null - if (data == null) - { - return default; - } - //Create a memory stream as a buffer - using VnMemoryStream ms = new(); - //Copy stream data to memory - data.CopyTo(ms, null); - if (ms.Length > 0) - { - //Rewind - ms.Position = 0; - //Recover data from stream - return JsonSerializer.Deserialize(ms.AsSpan(), type, options); - } - //Stream is empty - return default; - } + /// <summary> /// Attempts to deserialze a json object from a stream of UTF8 data /// </summary> @@ -315,7 +255,7 @@ namespace VNLib.Utils //Fill remaining bytes with padding chars for(; rounds < 8; rounds++) { - //Append trailing '=' + //Append trailing '=' padding character writer.Append('='); } } |