コード例 #1
0
ファイル: MessageStructure.cs プロジェクト: suncle/Scut
 /// <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
ファイル: MessageStructure.cs プロジェクト: suncle/Scut
 /// <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
        /// <summary>
        /// 写入Gzip压缩的Buffer,返回压缩后的长度
        /// </summary>
        /// <returns></returns>
        private int WriteGzipCompressBuffer(byte[] orgData)
        {
            byte[] buffer     = GzipUtils.EnCompress(orgData, 0, orgData.Length);
            int    gzipLength = buffer.Length;

            WriteByte(gzipLength);//分包时通过此长度计算来组包
            WriteByte(buffer);
            return(gzipLength);
        }
コード例 #4
0
        /// <summary>
        /// 读取消息头,如果有Gzip压缩时自动解压字节流
        /// </summary>
        /// <returns></returns>
        public MessageHead ReadHeadGzip()
        {
            MessageHead head = new MessageHead();

            head.HasGzip      = true;
            head.PacketLength = Length;
            //head.GzipLength = ReadInt();
            if (CheckGzipBuffer())
            {
                byte[] gzipData = ReadBuffer();
                //格式500+gzip( 1000+ XXXXXX)
                byte[] deZipData = GzipUtils.DeCompress(gzipData, 0, gzipData.Length);
                WriteByte(deZipData);
            }
            head.TotalLength = ReadInt();
            head.ErrorCode   = ReadInt();
            head.MsgId       = ReadInt();
            head.ErrorInfo   = ReadString();
            head.Action      = ReadInt();
            head.St          = ReadString();
            return(head);
        }
コード例 #5
0
ファイル: MessageStructure.cs プロジェクト: suncle/Scut
 private static byte[] CompressGzipBuffer(byte[] data)
 {
     return(GzipUtils.EnCompress(data, 0, data.Length));
 }