public void Visit(LzCompressed lz, byte data)
        {
            var start = index;

            (int runLength, int runOffset) = LZRun.ReadCompressedToken(buffer, ref start);
            Result = $"{runLength}:{runOffset}";
        }
示例#2
0
        public void Visit(LzCompressed lz, byte data)
        {
            if (!CurrentText.EndsWith(" "))
            {
                return;
            }
            var sections = CurrentText.Trim().Split(":");

            if (sections.Length != 2)
            {
                return;
            }
            if (!int.TryParse(sections[0], out int runLength))
            {
                return;
            }
            if (!int.TryParse(sections[1], out int runOffset))
            {
                return;
            }
            Result = true;
            if (runLength < 3 || runLength > 18)
            {
                ErrorText = "Run Length must be > 2 and < 19";
                return;
            }
            else if (runOffset < 1 || runOffset > 0x1000)
            {
                ErrorText = "Run Offset must be > 0 and <= 4096";
                return;
            }
            var result        = LZRun.CompressedToken((byte)runLength, (short)runOffset);
            var previousValue = Model.ReadMultiByteValue(memoryLocation, 2);

            CurrentChange.ChangeData(Model, memoryLocation, result[0]);
            CurrentChange.ChangeData(Model, memoryLocation + 1, result[1]);
            var run      = (LZRun)Model.GetNextRun(memoryLocation);
            int runIndex = memoryLocation - run.Start;

            if (!TryFixupLzRun(ref run, runIndex + 2))
            {
                Model.WriteMultiByteValue(memoryLocation, 2, CurrentChange, previousValue);
                ErrorText = $"Could not write {runLength}:{runOffset} without making the compressed data invalid.";
            }
            else
            {
                NewDataIndex = run.Start + runIndex + 2;
            }
        }
示例#3
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] = LzMagicIdentifier.Instance;
            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] = LzGroupHeader.Instance;
                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] = LzUncompressed.Instance;
                            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] = LzUncompressed.Instance;
                        cacheIndex++;
                        start++;
                    }
                }
            }
        }
 public void Visit(LzCompressed lz, byte data) => buffer.WriteMultiByteValue(index, 2, currentChange, 0xFF);
 public void Visit(LzCompressed lz, byte data)
 {
 }