-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
31 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 10 additions & 14 deletions
24
Source/Reloaded.Messaging.Serializer.MessagePack/MsgPackSerializer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,46 @@ | ||
using MessagePack; | ||
using MessagePack.Resolvers; | ||
using Reloaded.Messaging.Interfaces; | ||
|
||
namespace Reloaded.Messaging.Serializer.MessagePack | ||
{ | ||
public class MsgPackSerializer : ISerializer | ||
{ | ||
/// <summary> | ||
/// Uses LZ4 compression for serialization. | ||
/// Any custom resolver to pass to MessagePack. | ||
/// Default is <see cref="ContractlessStandardResolver.Instance"/> | ||
/// </summary> | ||
public bool UseLZ4 { get; private set; } | ||
public IFormatterResolver Resolver { get; private set; } = ContractlessStandardResolver.Instance; | ||
|
||
/// <summary> | ||
/// Any custom resolver to pass to MessagePack. | ||
/// Default is <see cref="MessagePack.Resolvers.ContractlessStandardResolver.Instance"/> | ||
/// Options for the MessagePack serializer. | ||
/// </summary> | ||
public IFormatterResolver Resolver { get; private set; } = global::MessagePack.Resolvers.ContractlessStandardResolver.Instance; | ||
public MessagePackSerializerOptions SerializerOptions { get; private set; } = MessagePackSerializerOptions.Standard; | ||
|
||
/// <summary> | ||
/// Creates a new instance of the MessagePack serializer. | ||
/// </summary> | ||
/// <param name="useLz4">Uses MessagePack's serializer with LZ4 compression.</param> | ||
/// <param name="resolver"> | ||
/// Custom resolver to pass to MessagePack, default is "Contractless Resolver" | ||
/// (<see cref="MessagePack.Resolvers.ContractlessStandardResolver.Instance"/>). | ||
/// (<see cref="ContractlessStandardResolver.Instance"/>). | ||
/// </param> | ||
public MsgPackSerializer(bool useLz4, IFormatterResolver resolver = null) | ||
public MsgPackSerializer(IFormatterResolver resolver = null) | ||
{ | ||
UseLZ4 = useLz4; | ||
if (resolver != null) | ||
Resolver = resolver; | ||
} | ||
|
||
|
||
/// <inheritdoc /> | ||
public TStruct Deserialize<TStruct>(byte[] serialized) | ||
{ | ||
return UseLZ4 ? LZ4MessagePackSerializer.Deserialize<TStruct>(serialized, Resolver) : | ||
MessagePackSerializer.Deserialize<TStruct>(serialized, Resolver); | ||
return MessagePackSerializer.Deserialize<TStruct>(serialized, SerializerOptions); | ||
} | ||
|
||
|
||
/// <inheritdoc /> | ||
public byte[] Serialize<TStruct>(ref TStruct item) | ||
{ | ||
return UseLZ4 ? LZ4MessagePackSerializer.Serialize(item, Resolver) : | ||
MessagePackSerializer.Serialize(item, Resolver); | ||
return MessagePackSerializer.Serialize(item, SerializerOptions); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters