using System.IO;
namespace MediaBrowser.Common.Serialization
{
///
/// 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.
///
public static class ProtobufSerializer
{
public static void SerializeToStream(T obj, Stream stream)
{
ProtoBuf.Serializer.Serialize(stream, obj);
}
public static T DeserializeFromStream(Stream stream)
{
return ProtoBuf.Serializer.Deserialize(stream);
}
public static void SerializeToFile(T obj, string file)
{
using (Stream stream = File.Open(file, FileMode.Create))
{
SerializeToStream(obj, stream);
}
}
public static T DeserializeFromFile(string file)
{
using (Stream stream = File.OpenRead(file))
{
return DeserializeFromStream(stream);
}
}
}
}