2012-09-05 23:40:44 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using ProtoBuf;
|
|
|
|
|
using ServiceStack.Text;
|
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.ApiInteraction
|
|
|
|
|
{
|
|
|
|
|
public static class DataSerializer
|
|
|
|
|
{
|
2012-09-06 14:00:44 +00:00
|
|
|
|
public static T DeserializeFromStream<T>(Stream stream, SerializationFormats format)
|
2012-09-05 23:40:44 +00:00
|
|
|
|
{
|
2012-09-06 14:00:44 +00:00
|
|
|
|
if (format == ApiInteraction.SerializationFormats.Protobuf)
|
|
|
|
|
{
|
|
|
|
|
return Serializer.Deserialize<T>(stream);
|
|
|
|
|
}
|
|
|
|
|
if (format == ApiInteraction.SerializationFormats.Jsv)
|
|
|
|
|
{
|
|
|
|
|
return TypeSerializer.DeserializeFromStream<T>(stream);
|
|
|
|
|
}
|
2012-09-05 23:40:44 +00:00
|
|
|
|
|
2012-09-06 14:00:44 +00:00
|
|
|
|
return JsonSerializer.DeserializeFromStream<T>(stream);
|
2012-09-05 23:40:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-09-06 14:00:44 +00:00
|
|
|
|
public static object DeserializeFromStream(Stream stream, SerializationFormats format, Type type)
|
2012-09-05 23:40:44 +00:00
|
|
|
|
{
|
2012-09-06 14:00:44 +00:00
|
|
|
|
if (format == ApiInteraction.SerializationFormats.Protobuf)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
if (format == ApiInteraction.SerializationFormats.Jsv)
|
|
|
|
|
{
|
|
|
|
|
return TypeSerializer.DeserializeFromStream(type, stream);
|
|
|
|
|
}
|
2012-09-05 23:40:44 +00:00
|
|
|
|
|
|
|
|
|
return JsonSerializer.DeserializeFromStream(type, stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Configure()
|
|
|
|
|
{
|
|
|
|
|
JsConfig.DateHandler = ServiceStack.Text.JsonDateHandler.ISO8601;
|
|
|
|
|
JsConfig.ExcludeTypeInfo = true;
|
|
|
|
|
JsConfig.IncludeNullValues = false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-06 14:00:44 +00:00
|
|
|
|
public static bool CanDeSerializeJsv
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-05 23:40:44 +00:00
|
|
|
|
}
|
|
|
|
|
}
|