formatFourdgsInspection function
The record table, in the column widths the Rust and TypeScript tools print.
Same columns in the same order, because the point of six tools that read one format is that their output can be diffed rather than interpreted.
Implementation
String formatFourdgsInspection(FourdgsInspection inspection) {
final FourdgsWalk walk = inspection.walk;
final FourdgsSummaryCoverage? coverage = inspection.coverage;
final StringBuffer out = StringBuffer();
void row(String a, String b, String c, String d, String e) => out.writeln(
'${a.padLeft(12)} ${b.padRight(18)} ${c.padLeft(14)} ${d.padLeft(14)} $e',
);
row('offset', 'record', 'content', 'total', 'crc');
row('0', '(magic)', '', '8', '-');
for (final FourdgsFrame frame in walk.records) {
row(
fourdgsCommas(frame.offset),
opcodeName(frame.opcode),
fourdgsCommas(frame.length),
fourdgsCommas(frame.total),
coverage?.cell(frame.offset, frame.total) ?? '-',
);
}
if (walk.trailingMagic) {
row(fourdgsCommas(walk.size - 8), '(magic)', '', '8', '-');
}
out.writeln();
out.writeln('${walk.recordCount} records, ${fourdgsCommas(walk.size)} bytes');
if (walk.recordsOmitted > 0) {
out.writeln(
'${walk.recordsOmitted} records omitted from the bounded table after '
'the first $maxFramedRecords; framing still covered the complete file',
);
}
final FourdgsCut? cut = walk.cut;
if (cut != null) {
out.writeln('truncated at byte ${fourdgsCommas(cut.at)}: ${cut.reason}');
final String last =
cut.insideARecord
? '; the last row is the record the file was cut inside'
: '';
out.writeln(
'the ${walk.intact} complete records above are the intact prefix, which '
'is what a streamed reader keeps$last',
);
} else if (!walk.trailingMagic) {
out.writeln('note: the file does not end with the magic');
}
final String? coverageError = inspection.coverageError;
if (coverageError != null) {
out.writeln(
'crc: the Footer frames cleanly but does not parse ($coverageError), so '
'nothing here could be checked',
);
} else if (coverage == null) {
out.writeln(
'crc: this file declares no summary checksum, so nothing here is covered',
);
} else {
out.writeln(
"crc: the Footer's summary checksum covers bytes "
'${fourdgsCommas(coverage.start)}..${fourdgsCommas(coverage.end)}; '
'`-` is a record it does not cover',
);
}
return out.toString();
}