mirror of
https://github.com/SabreTools/SabreTools.Serialization.git
synced 2026-07-08 18:06:41 +00:00
Add interfaces
This commit is contained in:
21
IByteSerializer.cs
Normal file
21
IByteSerializer.cs
Normal 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
20
IFileSerializer.cs
Normal 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
21
IModelSerializer.cs
Normal 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
22
IStreamSerializer.cs
Normal 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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user