using System.IO;
namespace MediaBrowser.Common.Serialization
{
///
/// This adds support for ServiceStack's proprietary JSV output format.
/// It's based on Json but the serializer performs faster and output runs about 10% smaller
/// http://www.servicestack.net/benchmarks/NorthwindDatabaseRowsSerialization.100000-times.2010-08-17.html
///
public static class JsvSerializer
{
public static void SerializeToStream(T obj, Stream stream)
{
ServiceStack.Text.TypeSerializer.SerializeToStream(obj, stream);
}
public static T DeserializeFromStream(Stream stream)
{
return ServiceStack.Text.TypeSerializer.DeserializeFromStream(stream);
}
public static void SerializeToFile(T obj, string file)
{
using (Stream stream = File.Open(file, FileMode.Create))
{
ServiceStack.Text.TypeSerializer.SerializeToStream(obj, stream);
}
}
public static T DeserializeFromFile(string file)
{
using (Stream stream = File.OpenRead(file))
{
return ServiceStack.Text.TypeSerializer.DeserializeFromStream(stream);
}
}
}
}