mirror of
https://github.com/morluto/rea.git
synced 2026-12-06 23:09:34 +00:00
refactor(journal): share 128-bit header ID reads (#17309)
This commit is contained in:
1 parent
a9832a6d61
commit
0f8d2db0fc
1 file changed
+7
-13
@@ -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. */
|
||||
|
||||
Reference in new issue
Block a user