Exemplo n.º 1
0
        private void UpdateCache(IDisposable scope, IReadOnlyList <byte> data)
        {
            previousScope = scope;
            cache         = new IDataFormat[Length];
            int start      = Start;
            var cacheIndex = 4;

            var decompressedLength = ReadHeader(data, ref start);

            cache[0] = new LzMagicIdentifier(Start);
            cache[1] = new Integer(Start + 1, 0, decompressedLength, 3);
            cache[2] = new Integer(Start + 1, 1, decompressedLength, 3);
            cache[3] = new Integer(Start + 1, 2, decompressedLength, 3);

            while (cacheIndex < cache.Length)
            {
                cache[cacheIndex] = new LzGroupHeader(start);
                var bitfield = data[start];
                cacheIndex++;
                start++;
                for (int i = 0; i < 8 && cacheIndex < cache.Length; i++)
                {
                    if (IsNextTokenCompressed(ref bitfield))
                    {
                        if (cacheIndex + 2 > cache.Length)
                        {
                            cache[cacheIndex] = new LzUncompressed(start);
                            cacheIndex++;
                        }
                        else
                        {
                            var(runLength, runOffset) = ReadCompressedToken(data, ref start);
                            cache[cacheIndex + 0]     = new LzCompressed(start - 2, 0, runLength, runOffset);
                            cache[cacheIndex + 1]     = new LzCompressed(start - 2, 1, runLength, runOffset);
                            cacheIndex += 2;
                        }
                    }
                    else
                    {
                        cache[cacheIndex] = new LzUncompressed(start);
                        cacheIndex++;
                        start++;
                    }
                }
            }
        }
Exemplo n.º 2
0
 public void Visit(LzGroupHeader lz, byte data)
 {
     if (!CurrentText.EndsWith(" "))
     {
         return;
     }
     if (byte.TryParse(CurrentText, NumberStyles.HexNumber, CultureInfo.CurrentCulture.NumberFormat, out var result))
     {
         var oldValue = Model[memoryLocation];
         CurrentChange.ChangeData(Model, memoryLocation, result);
         var run      = (LZRun)Model.GetNextRun(memoryLocation);
         int runIndex = memoryLocation - run.Start;
         Result = true;
         if (!TryFixupLzRun(ref run, runIndex + 1))
         {
             CurrentChange.ChangeData(Model, memoryLocation, oldValue);
             ErrorText = $"Could not write header {result:X2} without making the compressed data invalid.";
         }
         else
         {
             NewDataIndex = run.Start + runIndex + 1;
         }
     }
 }
Exemplo n.º 3
0
 public void Visit(LzGroupHeader lz, byte data) => Visit((None)null, data);
 public void Visit(LzGroupHeader lz, byte data)
 {
 }