2012-09-03 21:56:30 +00:00
using System ;
using System.IO ;
2012-08-23 05:45:26 +00:00
namespace MediaBrowser.Common.Serialization
{
2012-08-23 12:26:08 +00:00
/// <summary>
/// Protocol buffers is google's binary serialization format. This is a .NET implementation of it.
/// You have to tag your classes with some annoying attributes, but in return you get the fastest serialization around with the smallest possible output.
/// </summary>
2012-08-23 05:45:26 +00:00
public static class ProtobufSerializer
{
public static void SerializeToStream < T > ( T obj , Stream stream )
{
ProtoBuf . Serializer . Serialize < T > ( stream , obj ) ;
}
public static T DeserializeFromStream < T > ( Stream stream )
{
return ProtoBuf . Serializer . Deserialize < T > ( stream ) ;
}
2012-09-03 21:56:30 +00:00
public static object DeserializeFromStream ( Stream stream , Type type )
{
throw new NotImplementedException ( ) ;
}
2012-08-23 05:45:26 +00:00
public static void SerializeToFile < T > ( T obj , string file )
{
using ( Stream stream = File . Open ( file , FileMode . Create ) )
{
SerializeToStream < T > ( obj , stream ) ;
}
}
public static T DeserializeFromFile < T > ( string file )
{
using ( Stream stream = File . OpenRead ( file ) )
{
return DeserializeFromStream < T > ( stream ) ;
}
}
}
}