From 0f8d2db0fc8d6d7a14d34200d513116fcd8b7c2e Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Sun, 6 Dec 2026 08:08:26 +0800 Subject: [PATCH] refactor(journal): share 128-bit header ID reads (#17309) --- src/domain/linux/systemdJournal.ts | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/domain/linux/systemdJournal.ts b/src/domain/linux/systemdJournal.ts index 36168133ac0..00331ae70e1 100644 --- a/src/domain/linux/systemdJournal.ts +++ b/src/domain/linux/systemdJournal.ts @@ -153,8 +153,8 @@ const unsupported = (message: string): RegionDecodeFailure => ({ }); /** A 16-byte hexadecimal spelling of a 128-bit id; zeros stay distinguishable from all-ones. */ -const formatId128 = (bytes: Uint8Array): string => - Buffer.from(bytes).toString("hex"); +const readId128 = (bytes: Uint8Array, offset: number): string => + Buffer.from(bytes.subarray(offset, offset + 16)).toString("hex"); const flagNames = ( raw: number, @@ -232,25 +232,19 @@ const readFlagFacts = (view: BinaryReader) => { }; const readIdFacts = (bytes: Uint8Array, compatibleFlags: number) => ({ - file_id: formatId128(bytes.subarray(HEADER.fileId, HEADER.fileId + 16)), - machine_id: formatId128( - bytes.subarray(HEADER.machineId, HEADER.machineId + 16), - ), + file_id: readId128(bytes, HEADER.fileId), + machine_id: readId128(bytes, HEADER.machineId), // Bytes 56-71 are the legacy boot id unless `tail-entry-boot-id` is set. // Both readings keep the source value; only which name it carries changes. tail_entry_boot_id: (compatibleFlags & COMPATIBLE_TAIL_ENTRY_BOOT_ID) !== 0 - ? formatId128( - bytes.subarray(HEADER.tailEntryBootId, HEADER.tailEntryBootId + 16), - ) + ? readId128(bytes, HEADER.tailEntryBootId) : null, boot_id: (compatibleFlags & COMPATIBLE_TAIL_ENTRY_BOOT_ID) !== 0 ? null - : formatId128( - bytes.subarray(HEADER.tailEntryBootId, HEADER.tailEntryBootId + 16), - ), - seqnum_id: formatId128(bytes.subarray(HEADER.seqnumId, HEADER.seqnumId + 16)), + : readId128(bytes, HEADER.tailEntryBootId), + seqnum_id: readId128(bytes, HEADER.seqnumId), }); /** Facts for a header too short to anchor its object area; only what was read holds. */