示例#1
0
        /// <summary>
        /// Gets the underlying buffer 
        /// </summary>
        /// <param name="compressed">Whether we should compress or not.</param>
        /// <returns>The segment of the array </returns>
        public byte[] Flush(bool compressed)
        {
            if (compressed && this.Offset > 8)
            {
                // TODO: This should be seriously improved
                var packer = new CLZF();
                var uncompressedBytes = new byte[this.Offset - 8];
                System.Buffer.BlockCopy(this.Buffer, 8, uncompressedBytes, 0, uncompressedBytes.Length);
                var compressedBytes = new byte[this.Capacity];
                var size = packer.lzf_compress(uncompressedBytes, uncompressedBytes.Length, compressedBytes, compressedBytes.Length);
                System.Buffer.BlockCopy(compressedBytes, 0, this.Buffer, 8, size);

                // Update the new offset
                this.Offset = size + 8;
            }

            // Write the current size
            var length = this.Offset - 4;
            this.Buffer[0] = ((byte)(length >> 24));
            this.Buffer[1] = ((byte)(length >> 16));
            this.Buffer[2] = ((byte)(length >> 8));
            this.Buffer[3] = ((byte)length);

            // Return a copy of the buffer, avoiding any shared state
            var encoded = new byte[this.Offset];
            System.Buffer.BlockCopy(this.Buffer, 0, encoded, 0, this.Offset);
            return encoded;
        }
示例#2
0
    public void SendAudio(float[] f, int chan)
    {
        byte[] newBytes = CLZF.CompressAudio(f);

        //Debug.Log("Audio Length:" + newBytes.Length);

        CmdAudioSend(newBytes, chan);
    }
示例#3
0
    public void BeginHand(int hand, byte[] arrHand)
    {
        byte[] newHand = CLZF.Compress(arrHand);

        Debug.Log("Begin Hand:" + hand + " from " + arrHand.Length + " to " + newHand.Length);

        CmdBeginHand(hand, newHand);
    }
示例#4
0
        /// <summary>
        /// Begins reading a new packet.
        /// </summary>
        /// <param name="compressed">Whether the packet we are reding is compressed or not.</param>
        public void Begin(bool compressed)
        {
            if (compressed)
            {
                var compressedBuffer = new byte[this.Length - 8];
                var uncompressedBuffer = new byte[this.Capacity];
                System.Buffer.BlockCopy(this.Buffer, 8, compressedBuffer, 0, compressedBuffer.Length);

                var packer = new CLZF();
                var uncompressedSize = packer.lzf_decompress(compressedBuffer, compressedBuffer.Length, uncompressedBuffer, uncompressedBuffer.Length);
                System.Buffer.BlockCopy(uncompressedBuffer, 0, this.Buffer, 8, uncompressedSize);
                this.Length = uncompressedSize + 8;
            }
        }
    public static int constructor(IntPtr l)
    {
        int result;

        try
        {
            CLZF o = new CLZF();
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, o);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
    public static int Decompress_s(IntPtr l)
    {
        int result;

        try
        {
            byte[] inputBytes;
            LuaObject.checkArray <byte>(l, 1, out inputBytes);
            byte[] a = CLZF.Decompress(inputBytes);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, a);
            result = 2;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
    public static int lzf_compress_s(IntPtr l)
    {
        int result;

        try
        {
            byte[] input;
            LuaObject.checkArray <byte>(l, 1, out input);
            byte[] a;
            LuaObject.checkType <byte[]>(l, 2, out a);
            int i = CLZF.lzf_compress(input, ref a);
            LuaObject.pushValue(l, true);
            LuaObject.pushValue(l, i);
            LuaObject.pushValue(l, a);
            result = 3;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
示例#8
0
        void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUIEx.ObjectField <TextAsset>(ref assetToCompress, false);
            GUI.enabled = assetToCompress != null;
            if (GUILayout.Button("Compress"))
            {
                string src = AssetDatabase.GetAssetPath(assetToCompress);
                string dst = StringUtil.InsertSuffix(src, "_compress");
                dst = AssetDatabase.GenerateUniqueAssetPath(dst);

                byte[]     compressed = CLZF.Compress(assetToCompress.bytes);
                FileStream os         = new FileStream(dst, FileMode.CreateNew);
                os.Write(compressed, 0, compressed.Length);
                os.Close();
                AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
            }
            EditorGUILayout.EndHorizontal();
            GUI.enabled = true;
            EditorGUILayout.BeginHorizontal();
            EditorGUIEx.ObjectField <TextAsset>(ref assetToDecompress, false);
            GUI.enabled = assetToDecompress != null;
            if (GUILayout.Button("Decompress"))
            {
                string src = AssetDatabase.GetAssetPath(assetToDecompress);
                string dst = StringUtil.InsertSuffix(src, "_decompress");
                dst = AssetDatabase.GenerateUniqueAssetPath(dst);

                byte[]     decompressed = CLZF.Decompress(assetToCompress.bytes);
                FileStream os           = new FileStream(dst, FileMode.CreateNew);
                os.Write(decompressed, 0, decompressed.Length);
                os.Close();
                AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
            }
            EditorGUILayout.EndHorizontal();
            GUI.enabled = true;
        }
示例#9
0
 private static void DecompressAssetBundleCLZF(string input, FileStream outStream)
 {
     byte[] infile  = File.ReadAllBytes(input);
     byte[] outFile = CLZF.Decompress(infile);
     outStream.Write(outFile, 0, outFile.Length);
 }
示例#10
0
    public void SetLeapHand(int hand, byte[] arrHand)
    {
        byte[] newHand = CLZF.Compress(arrHand);

        CmdSetLeapHand(hand, newHand);
    }