// Copyright Epic Games, Inc. All Rights Reserved.
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using EpicGames.Core;
namespace EpicGames.Serialization
{
///
/// Extension methods for System.Net.Http
///
public static class HttpExtensions
{
///
/// Read content using CbSerializer, make sure the type T is correctly annotated to deserialize Compact Binary
///
/// Type to deserialize
/// The HTTP content you want to convert to type T read as byte content
/// Instance of type T
public static async Task ReadAsCompactBinaryAsync(this HttpContent content)
{
await using Stream s = await content.ReadAsStreamAsync();
byte[] b = await s.ReadAllBytesAsync();
return CbSerializer.Deserialize(b);
}
}
}