using System.IO;
using JD.Remoting;
namespace JD.Serialization
{
///
/// Adds serialization features to the blob.
///
public static class BlobExtensions
{
///
/// Pushes the object in its lua format.
///
public static void PushObject(this IBlob blob, T value)
where T : SpecialCustomTypeDescriptor
{
var serializer = new BinarySerializer();
using (var stream = new MemoryStream())
{
serializer.Serialize(stream, value);
var data = stream.ToArray();
blob.Push(data);
}
}
///
/// Pushes the object from its lua format.
///
public static void ExtractObject(this IBlob blob, T value)
where T : SpecialCustomTypeDescriptor
{
var serializer = new BinarySerializer();
var data = blob.ExtractBytes();
using (var stream = new MemoryStream(data))
{
serializer.Deserialize(stream, value);
}
}
}
}