//
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
//
namespace MUnique.OpenMU.Pathfinding.PreCalculation;
using System.IO;
///
/// Extension methods for paths serialization.
///
public static class PathsSerializeExtensions
{
///
/// The format in which the path infos will be serialized.
///
public enum PathInfoFormat
{
///
/// The compact format.
/// This format uses just 1 byte for end and 1 byte for next step.
/// It can only be used for maximumRange lower than 8, because of the space limitation.
///
Compact,
///
/// The normal format. Every point uses exactly 2 bytes.
///
Normal,
}
///
/// Serializes the path infos to the target stream.
///
/// The path infos.
/// The target stream.
/// The format.
public static void SerializeToStream(this IEnumerable pathInfos, Stream target, PathInfoFormat format)
{
IPathsSerializer serializer = format == PathInfoFormat.Compact ? new CompactPathsSerializer() as IPathsSerializer : new NormalPathsSerializer();
target.WriteByte((byte)format);
serializer.Serialize(pathInfos, target);
}
///
/// Deserializes the path infos from the source stream.
///
/// The source stream.
/// The path infos.
public static IEnumerable DeserializeFromStream(this Stream source)
{
var format = (PathInfoFormat)source.ReadByte();
IPathsSerializer serializer = format == PathInfoFormat.Compact ? new CompactPathsSerializer() as IPathsSerializer : new NormalPathsSerializer();
return serializer.Deserialize(source);
}
}