Exemplo n.º 1
0
        // -------------------------------------------------------------------------------

        private static unsafe byte[] PickleV0(byte *target, int targetLength, int sourceLength)
        {
            int diff = sourceLength - targetLength;
            int llen = diff == 0 ? 0
                : diff < 0x100 ? 1
                : diff < 0x10000 ? 2
                : 4;

            byte[] result = new byte[targetLength + 1 + llen];

            fixed(byte *resultPtr = result)
            {
                int  llenFlags = llen == 4 ? 3 : llen; // 2 bits
                byte flags     = (byte)((llenFlags << 6) | CurrentVersion);

                LZ4MemoryHelper.Poke8(resultPtr + 0, flags);

                if (llen == 1)
                {
                    LZ4MemoryHelper.Poke8(resultPtr + 1, (byte)diff);
                }
                else if (llen == 2)
                {
                    LZ4MemoryHelper.Poke16(resultPtr + 1, (ushort)diff);
                }
                else if (llen == 4)
                {
                    LZ4MemoryHelper.Poke32(resultPtr + 1, (uint)diff);
                }

                LZ4MemoryHelper.Move(resultPtr + llen + 1, target, targetLength);
            }

            return(result);
        }