mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-16 02:18:54 -07:00
Updated metro api interaction
This commit is contained in:
parent
99a679d328
commit
908695d88a
53
MediaBrowser.ApiInteraction.Metro/DataSerializer.cs
Normal file
53
MediaBrowser.ApiInteraction.Metro/DataSerializer.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using ProtoBuf;
|
||||
using ServiceStack.Text;
|
||||
|
||||
namespace MediaBrowser.ApiInteraction
|
||||
{
|
||||
public static class DataSerializer
|
||||
{
|
||||
public static T DeserializeFromStream<T>(Stream stream, SerializationFormats format)
|
||||
{
|
||||
if (format == ApiInteraction.SerializationFormats.Protobuf)
|
||||
{
|
||||
return Serializer.Deserialize<T>(stream);
|
||||
}
|
||||
if (format == ApiInteraction.SerializationFormats.Jsv)
|
||||
{
|
||||
return TypeSerializer.DeserializeFromStream<T>(stream);
|
||||
}
|
||||
|
||||
return JsonSerializer.DeserializeFromStream<T>(stream);
|
||||
}
|
||||
|
||||
public static object DeserializeFromStream(Stream stream, SerializationFormats format, Type type)
|
||||
{
|
||||
if (format == ApiInteraction.SerializationFormats.Protobuf)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
if (format == ApiInteraction.SerializationFormats.Jsv)
|
||||
{
|
||||
return TypeSerializer.DeserializeFromStream(type, stream);
|
||||
}
|
||||
|
||||
return JsonSerializer.DeserializeFromStream(type, stream);
|
||||
}
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
JsConfig.DateHandler = ServiceStack.Text.JsonDateHandler.ISO8601;
|
||||
JsConfig.ExcludeTypeInfo = true;
|
||||
JsConfig.IncludeNullValues = false;
|
||||
}
|
||||
|
||||
public static bool CanDeSerializeJsv
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -42,12 +42,10 @@
|
||||
<Compile Include="..\MediaBrowser.ApiInteraction\ApiClient.cs">
|
||||
<Link>ApiClient.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MediaBrowser.ApiInteraction\DataSerializer.cs">
|
||||
<Link>DataSerializer.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="..\MediaBrowser.ApiInteraction\SerializationFormats.cs">
|
||||
<Link>SerializationFormats.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="DataSerializer.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
Loading…
Reference in New Issue
Block a user