// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
using System;
using System.IO;
namespace FASTER.core
{
///
/// Object serializer interface
///
///
public interface IObjectSerializer
{
///
/// Begin serialization to given stream
///
///
void BeginSerialize(Stream stream);
///
/// Serialize object
///
///
void Serialize(ref T obj);
///
/// End serialization to given stream
///
void EndSerialize();
///
/// Begin deserialization from given stream
///
///
void BeginDeserialize(Stream stream);
///
/// Deserialize object
///
///
void Deserialize(ref T obj);
///
/// End deserialization from given stream
///
void EndDeserialize();
}
///
/// Serializer base class for binary reader and writer
///
///
public abstract class BinaryObjectSerializer : IObjectSerializer
{
///
/// Binary reader
///
protected BinaryReader reader;
///
/// Binary writer
///
protected BinaryWriter writer;
///
/// Begin deserialization
///
///
public void BeginDeserialize(Stream stream)
{
reader = new BinaryReader(stream);
}
///
/// Deserialize
///
///
public abstract void Deserialize(ref T obj);
///
/// End deserialize
///
public void EndDeserialize()
{
}
///
/// Begin serialize
///
///
public void BeginSerialize(Stream stream)
{
writer = new BinaryWriter(stream);
}
///
/// Serialize
///
///
public abstract void Serialize(ref T obj);
///
/// End serialize
///
public void EndSerialize()
{
writer.Dispose();
}
}
}