This is an automated email from the ASF dual-hosted git repository.

jinrongtong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/rocketmq-clients.git


The following commit(s) were added to refs/heads/master by this push:
     new c873edae [ISSUE #954] Add ZLib compression method in C# client (#955)
c873edae is described below

commit c873edae57e3a15c5354b7cbd1f1f7f64e074e2e
Author: Jack Tsai <tsunghanjackt...@outlook.com>
AuthorDate: Tue Mar 25 09:46:38 2025 +0800

    [ISSUE #954] Add ZLib compression method in C# client (#955)
    
    Co-authored-by: tsaitsung-han.tht <tsaitsung-han....@alibaba-inc.com>
---
 .github/workflows/csharp_build.yml           |  3 +--
 csharp/rocketmq-client-csharp/MessageView.cs | 13 +++++++++++--
 csharp/rocketmq-client-csharp/Utilities.cs   | 13 +++++++++++++
 3 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/csharp_build.yml 
b/.github/workflows/csharp_build.yml
index 590ba7b2..eb824f4b 100644
--- a/.github/workflows/csharp_build.yml
+++ b/.github/workflows/csharp_build.yml
@@ -24,6 +24,5 @@ jobs:
         working-directory: ./csharp
         run: |
           dotnet build
-          dotnet tool install -g dotnet-format
-          dotnet-format --check
+          dotnet format style
           dotnet test -l "console;verbosity=detailed"
diff --git a/csharp/rocketmq-client-csharp/MessageView.cs 
b/csharp/rocketmq-client-csharp/MessageView.cs
index aaa5ebb4..d38df9e6 100644
--- a/csharp/rocketmq-client-csharp/MessageView.cs
+++ b/csharp/rocketmq-client-csharp/MessageView.cs
@@ -147,7 +147,16 @@ namespace Org.Apache.Rocketmq
             {
                 case Proto.Encoding.Gzip:
                     {
-                        body = Utilities.DecompressBytesGzip(raw);
+                        // Gzip
+                        if (body[0] == 0x1f && body[1] == 0x8b)
+                        {
+                            body = Utilities.DecompressBytesGzip(raw);
+                        }
+                        // Zlib
+                        else if (body[0] == 0x78 || body[0] == 0x79)
+                        {
+                            body = Utilities.DecompressBytesZlib(raw);
+                        }
                         break;
                     }
                 case Proto.Encoding.Identity:
@@ -158,7 +167,7 @@ namespace Org.Apache.Rocketmq
                 default:
                     {
                         Logger.LogError($"Unsupported message encoding 
algorithm," +
-                                     $" topic={topic}, messageId={messageId}, 
bodyEncoding={bodyEncoding}");
+                                        $" topic={topic}, 
messageId={messageId}, bodyEncoding={bodyEncoding}");
                         break;
                     }
             }
diff --git a/csharp/rocketmq-client-csharp/Utilities.cs 
b/csharp/rocketmq-client-csharp/Utilities.cs
index 14e159e1..ef4616ea 100644
--- a/csharp/rocketmq-client-csharp/Utilities.cs
+++ b/csharp/rocketmq-client-csharp/Utilities.cs
@@ -154,5 +154,18 @@ namespace Org.Apache.Rocketmq
             gzipStream.CopyTo(outputStream);
             return outputStream.ToArray();
         }
+
+        public static byte[] DecompressBytesZlib(byte[] src)
+        {
+            if (src == null || src.Length == 0)
+            {
+                throw new ArgumentException("Input cannot be null or empty.", 
nameof(src));
+            }
+            using var inputStream = new MemoryStream(src);
+            using var zLibStream = new ZLibStream(inputStream, 
CompressionMode.Decompress);
+            using var outputStream = new MemoryStream();
+            zLibStream.CopyTo(outputStream);
+            return outputStream.ToArray();
+        }
     }
 }

Reply via email to