Add interfaces

This commit is contained in:
Matt Nadareski
2023-09-08 16:54:07 -04:00
parent a5ef893c10
commit 51ccc8ea43
4 changed files with 84 additions and 0 deletions

21
IByteSerializer.cs Normal file
View File

@@ -0,0 +1,21 @@
namespace SabreTools.Serialization
{
/// <summary>
/// Defines how to serialize to and from byte arrays
/// </summary>
public interface IByteSerializer<T>
{
/// <summary>
/// Deserialize a byte array into <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">Type of object to deserialize to</typeparam>
/// <param name="data">Byte array to parse</param>
/// <param name="offset">Offset into the byte array</param>
/// <returns>Filled object on success, null on error</returns>
#if NET48
T Deserialize(byte[] data, int offset);
#else
T? Deserialize(byte[]? data, int offset);
#endif
}
}

20
IFileSerializer.cs Normal file
View File

@@ -0,0 +1,20 @@
namespace SabreTools.Serialization
{
/// <summary>
/// Defines how to serialize to and from files
/// </summary>
public interface IFileSerializer<T>
{
/// <summary>
/// Deserialize a file into <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">Type of object to deserialize to</typeparam>
/// <param name="path">Path to deserialize from</param>
/// <returns>Filled object on success, null on error</returns>
#if NET48
T Deserialize(string path);
#else
T? Deserialize(string? path);
#endif
}
}

21
IModelSerializer.cs Normal file
View File

@@ -0,0 +1,21 @@
namespace SabreTools.Serialization
{
/// <summary>
/// Defines how to serialize to and from files
/// </summary>
public interface IFileSerializer<T, U>
{
/// <summary>
/// Deserialize a <typeparamref name="T"/> into <typeparamref name="u"/>
/// </summary>
/// <typeparam name="T">Type of object to deserialize from</typeparam>
/// <typeparam name="U">Type of object to deserialize to</typeparam>
/// <param name="obj">Object to deserialize from</param>
/// <returns>Filled object on success, null on error</returns>
#if NET48
U Deserialize(T obj);
#else
U? Deserialize(T? obj);
#endif
}
}

22
IStreamSerializer.cs Normal file
View File

@@ -0,0 +1,22 @@
using System.IO;
namespace SabreTools.Serialization
{
/// <summary>
/// Defines how to serialize to and from Streams
/// </summary>
public interface IStreamSerializer<T>
{
/// <summary>
/// Deserialize a Stream into <typeparamref name="T"/>
/// </summary>
/// <typeparam name="T">Type of object to deserialize to</typeparam>
/// <param name="data">Stream to parse</param>
/// <returns>Filled object on success, null on error</returns>
#if NET48
T Deserialize(Stream data);
#else
T? Deserialize(Stream? data);
#endif
}
}