-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathISerializer.cs
More file actions
43 lines (38 loc) · 1.47 KB
/
ISerializer.cs
File metadata and controls
43 lines (38 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
namespace DigitalRuby.SimpleCache;
/// <summary>
/// Interface for serializing cache objects to/from bytes
/// </summary>
public interface ISerializer
{
/// <summary>
/// Deserialize
/// </summary>
/// <param name="bytes">Bytes to deserialize</param>
/// <param name="type">Type of object to deserialize to</param>
/// <returns>Deserialized object or null if bytes is null or empty</returns>
object? Deserialize(byte[]? bytes, Type type);
/// <summary>
/// Deserialize using generic type parameter
/// </summary>
/// <typeparam name="T">Type of object to deserialize</typeparam>
/// <param name="bytes">Bytes</param>
/// <returns>Deserialized object or null if bytes is null or empty</returns>
T? Deserialize<T>(byte[]? bytes) => (T?)Deserialize(bytes, typeof(T));
/// <summary>
/// Serialize an object
/// </summary>
/// <param name="obj">Object to serialize</param>
/// <returns>Serialized bytes or null if obj is null</returns>
byte[]? Serialize(object? obj);
/// <summary>
/// Serialize using generic type parameter
/// </summary>
/// <typeparam name="T">Type of object</typeparam>
/// <param name="obj">Object to serialize</param>
/// <returns>Serialized bytes or null if obj is null</returns>
byte[]? Serialize<T>(T? obj) => Serialize(obj);
/// <summary>
/// Get a short description for the serializer, i.e. json or json-lz4.
/// </summary>
string Description { get; }
}