示例#1
0
 /// <summary>
 /// 读取消息头,如果有Gzip压缩时自动解压字节流
 /// </summary>
 /// <returns></returns>
 /// <exception cref="OverflowException"></exception>
 public MessageHead ReadHeadGzip()
 {
     try
     {
         MessageHead head = new MessageHead();
         head.HasGzip      = true;
         head.PacketLength = Length;
         if (CheckGzipBuffer())
         {
             byte[] gzipData = PopBuffer();
             head.GzipLength = gzipData.Length;
             //gzip格式500+gzip( 1000+ XXXXXX)
             byte[] deZipData = GzipUtils.DeCompress(gzipData, 0, gzipData.Length);
             WriteByte(deZipData);
             Reset();
         }
         head.TotalLength = ReadInt();
         head.ErrorCode   = ReadInt();
         head.MsgId       = ReadInt();
         head.ErrorInfo   = ReadString();
         head.Action      = ReadInt();
         head.St          = ReadString();
         return(head);
     }
     catch (Exception ex)
     {
         string error = string.Format("read to {0}/{1}pos error,\r\nbytes:{2}", Offset, Length, ToHexString());
         throw new OverflowException(error, ex);
     }
 }
示例#2
0
 /// <summary>
 /// 自动压缩
 /// </summary>
 /// <param name="buffer"></param>
 /// <returns>返回压缩后的字节</returns>
 public byte[] CompressBuffer(byte[] buffer)
 {
     if (buffer.Length > EnableGzipMinByte)
     {
         return(GzipUtils.EnCompress(buffer, 0, buffer.Length));
     }
     return(buffer);
 }
示例#3
0
 private static byte[] CompressGzipBuffer(byte[] data)
 {
     return(GzipUtils.EnCompress(data, 0, data.Length));
 }