示例#1
0
        public static List <LZNT1_Data> GenerateFromLZ77Match(byte[] arg, LZ77Match match, ref int processedBytes)
        {
            var result = new List <LZNT1_Data>();

            int remainingLength = match.Length;

            while (remainingLength >= 3)
            {
                var compressedWord   = new LZNT1_CompressedWord();
                int displacementBits = GetDisplcaementBits(processedBytes);
                int maximumLength    = GetMaximumLength(processedBytes);
                int length           = Math.Min(remainingLength, maximumLength);
                compressedWord.Value  = 0;
                compressedWord.Value |= (length - 3) & ((1 << (16 - displacementBits)) - 1);
                compressedWord.Value |= ((match.Distance - 1) & ((1 << displacementBits) - 1)) << (16 - displacementBits);
                result.Add(compressedWord);
                processedBytes  += length;
                remainingLength -= length;
            }
            for (int i = 0; i < remainingLength; i++)
            {
                var literal = new LZNT1_Literal();
                literal.Literal = arg[processedBytes - match.Distance];
                result.Add(literal);
                processedBytes++;
            }
            return(result);
        }
示例#2
0
        public static LZNT1_Literal GenerateFromLZ77Literal(LZ77Literal literal, ref int processedBytes)
        {
            var result = new LZNT1_Literal();

            result.Literal = literal.Literal;
            processedBytes++;
            return(result);
        }
示例#3
0
        public override object Unmarshal(LittleEndianByteBuffer buffer, ref int offset)
        {
            var result = new LZNT1_Literal();

            result.Literal = (byte)buffer.ReadBytes(offset, 1);
            offset++;

            return(result);
        }
示例#4
0
        public static List <LZNT1_Data> GenerateFromLZ77Symbol(byte[] arg, LZ77Symbol symbol, ref int processedBytes)
        {
            var result = new List <LZNT1_Data>();

            if (symbol is LZ77Literal)
            {
                var literal = symbol as LZ77Literal;
                result.Add(LZNT1_Literal.GenerateFromLZ77Literal(literal, ref processedBytes));
            }
            else if (symbol is LZ77Match)
            {
                var match = symbol as LZ77Match;
                result.AddRange(LZNT1_CompressedWord.GenerateFromLZ77Match(arg, match, ref processedBytes));
            }
            else if (symbol is LZ77EOF)
            {
                // do nothing to EOF.
            }
            else
            {
                throw new XcaException("Unreachable code!");
            }
            return(result);
        }