Exemple #1
0
        private static List <string> ReadMainDataRaw(string allLines)
        {
            var(lines, options) = ReadHeader(allLines);

            CheckForCompatibleVersion(options);

            // always apply options in same order here and in saving function
            if (options.Exists(s => s == "compress_table_1"))
            {
                SubstitutionCompression.DecodeCompression_Table1(ref lines);
            }

            if (options.Exists(s => s == "compress_groupblocks"))
            {
                RepeaterCompression.Decompress(ref lines);
            }
            return(lines);
        }
Exemple #2
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");
            }
        }