public static Packet Compress(Packet p) { int length; byte[] source = p.Compile(false, out length); if (length > 100 && length < 60000) { byte[] dest = new byte[(int)(length * 1.001) + 1]; int destSize = dest.Length; ZLibError error = ZLib.compress2(dest, ref destSize, source, length, ZLibCompressionLevel.Z_BEST_COMPRESSION); // best compression (slowest) if (error != ZLibError.Z_OK) { Console.WriteLine("WARNING: Unable to compress admin packet, zlib error: {0}", error); return(p); } else { return(new AdminCompressedPacket(dest, destSize, length)); } } else { return(p); } }
public static Packet Compress(Packet p) { byte[] source = p.Compile(false); if (source.Length > 100 && source.Length < 60000) { byte[] dest = new byte[(int)(source.Length * 1.001) + 1]; int destSize = dest.Length; ZLibError error = ZLib.compress2(dest, ref destSize, source, source.Length, ZLibCompressionLevel.Z_BEST_COMPRESSION); // best compression (slowest) if (error != ZLibError.Z_OK) { log.Error(String.Format("Unable to compress admin packet, zlib error: {0}", error)); return(p); } else { return(new AdminCompressedPacket(dest, destSize, source.Length)); } } else { return(p); } }