Ejemplo n.º 1
0
        public void Write(IFormatWriter writer, RomBytes instance)
        {
            var options = new List <string>
            {
                $"version:{CurrentDataFormatVersion}",
            };

            var romByteEncoding = new RomByteEncoding();

            var lines = new List <string>();

            foreach (var rb in instance)
            {
                var encodedTxt = romByteEncoding.EncodeByte(rb);
                lines.Add(encodedTxt);

                // debug check, optional:
#if EXTRA_DEBUG_CHECKS
                var decoded = romByteEncoding.DecodeRomByte(encodedTxt);
                Debug.Assert(decoded.EqualsButNoRomByte(rb));
#endif
            }

            if (CompressGroupBlock)
            {
                options.Add("compress_groupblocks");
                RepeaterCompression.Compress(ref lines);
            }

            if (CompressUsingTable1)
            {
                options.Add("compress_table_1");
                SubstitutionCompression.EncodeCompression_Table1(ref lines);
            }

            writer.Content($"\n{string.Join(",", options)}\n");

            foreach (var line in lines)
            {
                writer.Content(line + "\n");
            }
        }
Ejemplo n.º 2
0
        private static RomByte[] DecodeRomBytes(IReadOnlyList <string> allLines, int startIndex, int count)
        {
            // perf: allocate all at once, don't use List.Add() one at a time
            var romBytes        = new RomByte[count];
            var romByteEncoding = new RomByteEncoding();
            var i = 0;

            try
            {
                while (i < count)
                {
                    var line = allLines[startIndex + i];
                    romBytes[i] = romByteEncoding.DecodeRomByte(line);
                    ++i;
                }
            }
            catch (Exception ex)
            {
                ex.Data.Add("ParseLineNum", "Near line# " + (startIndex + i));
                throw;
            }

            return(romBytes);
        }