Skip to content

Commit

Permalink
Merge pull request #80 from dragonfruitnetwork/apiclient-cleanup
Browse files Browse the repository at this point in the history
serializerutils cleanup
  • Loading branch information
aspriddell authored Sep 8, 2021
2 parents 163543b + e00b2d2 commit c93d15c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
10 changes: 0 additions & 10 deletions DragonFruit.Common.Data/Extensions/HashExtensions.cs

This file was deleted.

19 changes: 19 additions & 0 deletions DragonFruit.Common.Data/Serializers/ApiSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;

#pragma warning disable 618
Expand Down Expand Up @@ -37,5 +38,23 @@ public Encoding Encoding

public abstract HttpContent Serialize<T>(T input) where T : class;
public abstract T Deserialize<T>(Stream input) where T : class;

/// <summary>
/// Converts a <see cref="Stream"/> serialized in the <see cref="ApiSerializer"/> to the <see cref="HttpContent"/> equivalent
/// </summary>
/// <param name="stream">The stream to convert</param>
protected HttpContent GetHttpContent(Stream stream)
{
stream.Seek(0, SeekOrigin.Begin);
var content = new StreamContent(stream);

content.Headers.ContentLength = stream.Length;
content.Headers.ContentType = new MediaTypeHeaderValue(ContentType)
{
CharSet = Encoding.HeaderName
};

return content;
}
}
}
2 changes: 2 additions & 0 deletions DragonFruit.Common.Data/Utils/SerializerUtils.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// DragonFruit.Common Copyright 2021 DragonFruit Network
// Licensed under the MIT License. Please refer to the LICENSE file at the root of this project for details

using System;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
Expand All @@ -10,6 +11,7 @@ namespace DragonFruit.Common.Data.Utils
{
public static class SerializerUtils
{
[Obsolete("Now available as ApiSerializer.GetHttpContent(stream). This will be removed in the future")]
public static HttpContent ProcessStream(ISerializer serializer, Stream stream)
{
stream.Seek(0, SeekOrigin.Begin);
Expand Down

0 comments on commit c93d15c

Please sign in to comment.