Пример #1
0
        public void AddOutgoingPacket(byte[] packet, PacketType packetType)
        {
            lock (sendLoopLock)
            {
                if (Closed)
                {
                    return;
                }

                var addFlags = PacketFlags.None;
                if (NeedsSplitting(packet.Length))
                {
                    if (packetType == PacketType.Voice || packetType == PacketType.VoiceWhisper)
                    {
                        return;                         // Exception maybe ??? This happens when a voice packet is bigger then the allowed size
                    }
                    packet    = QuickLZ.Compress(packet, 1);
                    addFlags |= PacketFlags.Compressed;

                    if (NeedsSplitting(packet.Length))
                    {
                        foreach (var splitPacket in BuildSplitList(packet, packetType))
                        {
                            AddOutgoingPacket(splitPacket, addFlags);
                        }
                        return;
                    }
                }
                AddOutgoingPacket(new OutgoingPacket(packet, packetType), addFlags);
            }
        }
Пример #2
0
 private void DoCompressAndWrite()
 {
     byte[] compressedData = QuickLZ.Compress(gatherBuffer, 3);
     length += compressedData.Length;
     //Console.WriteLine ("send, gather buffer="+gatherBuffer.Length+", gatherpos="+currentGatherPos+", compressed block="+compressedData.Length);
     inputStream.Write(compressedData, 0, compressedData.Length);
     //Console.WriteLine ("sent.");
     //currentGatherPos = 0;
 }
Пример #3
0
 /// <summary>
 /// Clears all buffers for this stream and causes any buffered data to be written to the underlying device.
 /// </summary>
 /// <exception cref="T:System.IO.IOException">
 /// An I/O error occurs.
 /// </exception>
 public override void Flush()
 {
     if (_writeBufferOffset > 0)
     {
         //int compressedLength = QuickLZ.Compress(_writeBuffer, _compressedBuffer,_writeBufferOffset);
         _compressedBuffer = QuickLZ.Compress(_writeBuffer, 3);
         outputStream.Write(_compressedBuffer, 0, _compressedBuffer.Length);
         _writeBufferOffset = 0;
         length            += _compressedBuffer.Length;
     }
 }
Пример #4
0
        public void SendPacket(IPacket packet)
        {
            using (var ms = new MemoryStream())
            {
                serializer.Serialize(ms, packet);

                byte[] packetBytes = QuickLZ.Compress(ms.ToArray(), 3);
                SendData(packetBytes);
            }

            PacketSent?.Invoke(this, EventArgs.Empty);
        }
Пример #5
0
 private static void RunGeneralTest(int level)
 {
     byte[] original = File.ReadAllBytes("./Flower.bmp");
     var qlz = new QuickLZ(level);
     int sizeC = qlz.SizeCompressed(original);
     var compressedBytes = new byte[sizeC];
     qlz.Compress(original, compressedBytes, original.Length);
     var result = new byte[original.Length];
     qlz.Decompress(compressedBytes, result);
     for (int i = 0; i < original.Length; i++)
     {
         Assert.AreEqual(original[i], result[i]);
     }
 }
Пример #6
0
        private static void RunGeneralTest(int level)
        {
            byte[] original        = File.ReadAllBytes("./Flower.bmp");
            var    qlz             = new QuickLZ(level);
            int    sizeC           = qlz.SizeCompressed(original);
            var    compressedBytes = new byte[sizeC];

            qlz.Compress(original, compressedBytes, original.Length);
            var result = new byte[original.Length];

            qlz.Decompress(compressedBytes, result);
            for (int i = 0; i < original.Length; i++)
            {
                Assert.AreEqual(original[i], result[i]);
            }
        }