Skip to content

Commit

Permalink
ZLIB格式RFC1950,要去掉头部两个字节
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Mar 19, 2021
1 parent 5c4c9ab commit c68d9ac
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
7 changes: 4 additions & 3 deletions NewLife.RocketMQ/Protocol/MessageExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ public Boolean Read(Stream stream, Object context = null)
if ((SysFlag & 1) == 1)
{
/*uncompress*/
//Body = Body.Decompress();
var gs = new MemoryStream(Body);
Body = gs.DecompressGZip().ReadBytes();
// ZLIB格式RFC1950,要去掉头部两个字节
Body = Body.ReadBytes(2).Decompress();
//var gs = new MemoryStream(Body);
//Body = gs.DecompressGZip().ReadBytes();
}

// 主题
Expand Down
22 changes: 21 additions & 1 deletion Test/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using NewLife.RocketMQ.Common;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Threading;

Expand All @@ -15,7 +17,7 @@ static void Main(String[] args)
{
XTrace.UseConsole();

Test1();
Test4();

Console.WriteLine("OK!");
Console.ReadKey();
Expand Down Expand Up @@ -150,5 +152,23 @@ static void Test3()
Console.WriteLine("{0} {1} {2}", i, bk.Name, times - 1);
}
}

static void Test4()
{
var a1 = File.ReadAllBytes("a1".GetFullPath());
var a2 = File.ReadAllBytes("a2".GetFullPath());

//var ms = new MemoryStream(a1);
//ms.Position += 2;
//var ds = new DeflateStream(ms, CompressionMode.Decompress);
//var buf = ds.ReadBytes();

var buf = a1.ReadBytes(2).Decompress();

var rs = a2.ToBase64() == buf.ToBase64();
Console.WriteLine(rs);

Console.WriteLine(buf.ToStr());
}
}
}

0 comments on commit c68d9ac

Please sign in to comment.