-
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.
Merge pull request #120 from itsharppro/dev
- Loading branch information
Showing
16 changed files
with
265 additions
and
128 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
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
42 changes: 42 additions & 0 deletions
42
src/Paralax.HTTP/src/Paralax.HTTP/MessagePackHttpClientSerializer.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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using MessagePack; | ||
using MessagePack.Resolvers; | ||
|
||
namespace Paralax.HTTP | ||
{ | ||
public class MessagePackHttpClientSerializer : IHttpClientSerializer | ||
{ | ||
private readonly MessagePackSerializerOptions _options; | ||
|
||
public MessagePackHttpClientSerializer(MessagePackSerializerOptions options = null) | ||
{ | ||
_options = options ?? MessagePackSerializerOptions.Standard | ||
.WithResolver(ContractlessStandardResolver.Instance) | ||
.WithCompression(MessagePackCompression.Lz4BlockArray) | ||
.WithSecurity(MessagePackSecurity.UntrustedData); | ||
} | ||
|
||
public string Serialize<T>(T value) | ||
{ | ||
var bytes = MessagePackSerializer.Serialize(value, _options); | ||
return System.Convert.ToBase64String(bytes); | ||
} | ||
|
||
public async Task SerializeAsync<T>(Stream stream, T value) | ||
{ | ||
await MessagePackSerializer.SerializeAsync(stream, value, _options); | ||
} | ||
|
||
public async ValueTask<T> DeserializeAsync<T>(Stream stream) | ||
{ | ||
return await MessagePackSerializer.DeserializeAsync<T>(stream, _options); | ||
} | ||
|
||
public T Deserialize<T>(string base64) | ||
{ | ||
var bytes = System.Convert.FromBase64String(base64); | ||
return MessagePackSerializer.Deserialize<T>(bytes, _options); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.