mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 11:13:21 +00:00
* fix(artifacts): require each reader traversal to declare its coverage * docs(artifacts): state that silent traversals report unknown coverage
53 lines
1.6 KiB
TypeScript
53 lines
1.6 KiB
TypeScript
import {
|
|
HEX_RECORD_ENCODING_LABELS,
|
|
createHexRecordDecoder,
|
|
type HexRecordImage,
|
|
} from "../domain/firmware/hexRecords.js";
|
|
import type { HexRecordEncoding } from "../domain/firmware/hexRecordSyntax.js";
|
|
import {
|
|
DecodedRegionArtifactReader,
|
|
regionFileName,
|
|
type RegionDecoding,
|
|
} from "./DecodedRegionArtifactReader.js";
|
|
import type { StableRegularFileDescriptor } from "../filesystem/RegularFile.js";
|
|
|
|
const hexRecordRegions = (
|
|
format: HexRecordEncoding,
|
|
): RegionDecoding<HexRecordImage> => ({
|
|
label: HEX_RECORD_ENCODING_LABELS[format],
|
|
keyPrefix: "hex-records",
|
|
createDecoder: (fileBytes) => createHexRecordDecoder(format, fileBytes),
|
|
describe: (image) => ({
|
|
metadata: image.metadata,
|
|
regions: image.regions.map((region) => ({
|
|
path: regionFileName(region.start, region.end),
|
|
byteOffset: null,
|
|
formatMetadata: {
|
|
kind: "hex-record-region",
|
|
start_address: region.start,
|
|
end_address: region.end,
|
|
length: region.bytes.length,
|
|
record_count: region.recordCount,
|
|
first_line: region.firstLine,
|
|
last_line: region.lastLine,
|
|
},
|
|
bytes: region.bytes,
|
|
})),
|
|
coverage: {
|
|
status: image.terminated ? "complete" : "unknown",
|
|
limitations: image.limitations,
|
|
},
|
|
}),
|
|
});
|
|
|
|
/** Decode Intel HEX or S-record text into address-contiguous region entries. */
|
|
export class HexRecordArtifactReader extends DecodedRegionArtifactReader<HexRecordImage> {
|
|
constructor(
|
|
path: string,
|
|
format: HexRecordEncoding,
|
|
admitted?: StableRegularFileDescriptor,
|
|
) {
|
|
super(path, format, hexRecordRegions(format), admitted);
|
|
}
|
|
}
|