-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: segregated serializer and compressor interfaces
- Loading branch information
1 parent
76e9ccc
commit ce7b5d7
Showing
52 changed files
with
467 additions
and
260 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
namespace KafkaFlow.Compressor.Gzip | ||
{ | ||
using System.IO; | ||
using System.IO.Compression; | ||
|
||
/// <summary> | ||
/// A GZIP message decompressor | ||
/// </summary> | ||
public class GzipMessageDecompressor : IMessageDecompressor | ||
{ | ||
/// <inheritdoc /> | ||
public byte[] Decompress(byte[] message) | ||
{ | ||
using var outputStream = new MemoryStream(); | ||
using var inputStream = new MemoryStream(message); | ||
|
||
using (var gzipStream = new GZipStream(inputStream, CompressionMode.Decompress)) | ||
{ | ||
gzipStream.CopyTo(outputStream); | ||
} | ||
|
||
return outputStream.ToArray(); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
namespace KafkaFlow.Serializer | ||
{ | ||
using System; | ||
using System.IO; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
/// <summary> | ||
/// A message deserializer using System.Text.Json library | ||
/// </summary> | ||
public class JsonCoreDeserializer : IDeserializer | ||
{ | ||
private readonly JsonSerializerOptions serializerOptions; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="JsonCoreDeserializer"/> class. | ||
/// </summary> | ||
/// <param name="options">Json serializer options</param> | ||
public JsonCoreDeserializer(JsonSerializerOptions options) | ||
{ | ||
this.serializerOptions = options; | ||
} | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="JsonCoreDeserializer"/> class. | ||
/// </summary> | ||
public JsonCoreDeserializer() | ||
: this(new JsonSerializerOptions()) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
public async Task<object> DeserializeAsync(Stream input, Type type, ISerializerContext context) | ||
{ | ||
return await JsonSerializer | ||
.DeserializeAsync(input, type, this.serializerOptions) | ||
.ConfigureAwait(false); | ||
} | ||
} | ||
} |
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.