Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use Snappier library instead of Snappy.Standard #266

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/Pulsar.Client/Internal/Compression.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ open Pulsar.Client.Api
open Pulsar.Client.Common
open ComponentAce.Compression.Libs.zlib
open K4os.Compression.LZ4
open Snappy
open Snappier
open ZstdNet

type ICompressionCodec =
Expand Down Expand Up @@ -79,23 +79,21 @@ module internal CompressionCodec =
interface ICompressionCodec with
member this.Encode payload =
let length = (int payload.Length)
let source: byte[] = length |> ArrayPool.Shared.Rent
let target: byte[] = SnappyCodec.GetMaxCompressedLength length |> ArrayPool.Shared.Rent
let target: byte[] = Snappy.GetMaxCompressedLength length |> ArrayPool.Shared.Rent
try
let sourceSpan = payload.ToArray().AsSpan()
sourceSpan.CopyTo(source)
let count = SnappyCodec.Compress(source, 0, length, target, 0)
let sourceArray = payload.ToArray()
let targetSpan = target.AsSpan()
let count = Snappy.Compress(sourceArray, targetSpan)
let ms = MemoryStreamManager.GetStream()
ms.Write(target.AsSpan(0, count))
ms.Write(targetSpan.Slice(0, count))
ms
finally
payload.Dispose()
source |> ArrayPool.Shared.Return
target |> ArrayPool.Shared.Return
member this.Decode (uncompressedSize, payload) =
let target: byte[] = uncompressedSize |> ArrayPool.Shared.Rent
try
SnappyCodec.Uncompress(payload.ToArray(), 0, int payload.Length, target, 0) |> ignore
Snappy.Decompress(payload.ToArray(), target) |> ignore
let ms = MemoryStreamManager.GetStream(null, uncompressedSize)
ms.Write(target, 0, uncompressedSize)
ms
Expand All @@ -104,7 +102,7 @@ module internal CompressionCodec =
target |> ArrayPool.Shared.Return
member this.Decode (uncompressedSize, bytes, payloadLength) =
let target = Array.zeroCreate uncompressedSize
SnappyCodec.Uncompress(bytes, 0, payloadLength, target, 0) |> ignore
Snappy.Decompress(bytes.AsSpan().Slice(0, payloadLength), target.AsSpan()) |> ignore
target

type ZstdCompression() =
Expand Down
2 changes: 1 addition & 1 deletion src/Pulsar.Client/Pulsar.Client.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<PackageReference Include="protobuf-net" Version="3.2.30" />
<PackageReference Include="zlib.net-mutliplatform" Version="1.0.6" />
<PackageReference Include="K4os.Compression.LZ4" Version="1.3.6" />
<PackageReference Include="Snappy.Standard" Version="0.2.0" />
<PackageReference Include="Snappier" Version="1.1.6" />
<PackageReference Include="ZstdNet" Version="1.4.5" />
<PackageReference Include="Pipelines.Sockets.Unofficial" Version="2.2.8" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
Expand Down
Loading