2012-09-06 14:05:35 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
2012-09-06 14:44:45 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2012-09-06 14:05:35 +00:00
|
|
|
|
using ProtoBuf;
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
2012-09-06 18:38:29 +00:00
|
|
|
|
else if (format == ApiInteraction.SerializationFormats.Jsv)
|
2012-09-06 14:05:35 +00:00
|
|
|
|
{
|
2012-09-06 14:44:45 +00:00
|
|
|
|
throw new NotImplementedException();
|
2012-09-06 14:05:35 +00:00
|
|
|
|
}
|
2012-09-06 18:38:29 +00:00
|
|
|
|
else if (format == ApiInteraction.SerializationFormats.Json)
|
2012-09-06 14:44:45 +00:00
|
|
|
|
{
|
2012-09-06 18:38:29 +00:00
|
|
|
|
using (StreamReader streamReader = new StreamReader(stream))
|
2012-09-06 14:44:45 +00:00
|
|
|
|
{
|
2012-09-06 18:38:29 +00:00
|
|
|
|
using (JsonReader jsonReader = new JsonTextReader(streamReader))
|
|
|
|
|
{
|
|
|
|
|
return JsonSerializer.Create(new JsonSerializerSettings()).Deserialize<T>(jsonReader);
|
|
|
|
|
}
|
2012-09-06 14:44:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-06 18:38:29 +00:00
|
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
2012-09-06 14:05:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static object DeserializeFromStream(Stream stream, SerializationFormats format, Type type)
|
|
|
|
|
{
|
|
|
|
|
if (format == ApiInteraction.SerializationFormats.Protobuf)
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
2012-09-06 18:38:29 +00:00
|
|
|
|
else if (format == ApiInteraction.SerializationFormats.Jsv)
|
2012-09-06 14:05:35 +00:00
|
|
|
|
{
|
2012-09-06 14:44:45 +00:00
|
|
|
|
throw new NotImplementedException();
|
2012-09-06 14:05:35 +00:00
|
|
|
|
}
|
2012-09-06 18:38:29 +00:00
|
|
|
|
else if (format == ApiInteraction.SerializationFormats.Json)
|
2012-09-06 14:44:45 +00:00
|
|
|
|
{
|
2012-09-06 18:38:29 +00:00
|
|
|
|
using (StreamReader streamReader = new StreamReader(stream))
|
2012-09-06 14:44:45 +00:00
|
|
|
|
{
|
2012-09-06 18:38:29 +00:00
|
|
|
|
using (JsonReader jsonReader = new JsonTextReader(streamReader))
|
|
|
|
|
{
|
|
|
|
|
return JsonSerializer.Create(new JsonSerializerSettings()).Deserialize(jsonReader, type);
|
|
|
|
|
}
|
2012-09-06 14:44:45 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-09-06 18:38:29 +00:00
|
|
|
|
|
|
|
|
|
throw new NotImplementedException();
|
2012-09-06 14:05:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void Configure()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static bool CanDeSerializeJsv
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|