diff --git a/new-log-viewer/src/services/decoders/ClpArchiveDecoder/ClpArchiveDecoder.ts b/new-log-viewer/src/services/decoders/ClpArchiveDecoder/ClpArchiveDecoder.ts index 871f2fd9..35a3c79e 100644 --- a/new-log-viewer/src/services/decoders/ClpArchiveDecoder/ClpArchiveDecoder.ts +++ b/new-log-viewer/src/services/decoders/ClpArchiveDecoder/ClpArchiveDecoder.ts @@ -37,7 +37,7 @@ class ClpArchiveDecoder implements Decoder { * invoked publicly. Instead, use ClpArchiveDecoder.create() to create a * new instance of the class. * - * @param dataInputStream Byte stream containing segment data with offset + * @param dataInputStream Byte array containing single file archive with offset * at start of segments. * @param segmentSizes Byte sizes for segments. * @param segmentInfos Metadata for segments. @@ -59,13 +59,11 @@ class ClpArchiveDecoder implements Decoder { } /** - * Creates a new ClpArchiveDecoder. Deserializes the single archive header, - * the CLP archive metadata, and the archive dictionaries. The returned - * decoder is in a state to deserialize segment data. + * Creates a new ClpArchiveDecoder. Deserializes the single archive header + * metadata, the CLP archive metadata, and the archive dictionaries. The + * returned decoder state is ready to deserialize segment data. * - * @param dataArray Byte array containing single file archive. When this - * method returns, the position of the data array will be the start of - * segment data. + * @param dataArray Byte array containing single file archive. * @return A Promise that resolves to the created ClpArchiveDecoder instance. */ static async create (dataArray: Uint8Array): Promise { @@ -80,7 +78,7 @@ class ClpArchiveDecoder implements Decoder { const segmentInfos: SegmentInfo[] = await querySegmentInfos( dataInputStream, - nonSegmentSizes.metadataDB + nonSegmentSizes.metadataDb ); const logTypeDict: Uint8Array[] = await ClpArchiveDecoder.#deserializeDictionary( @@ -152,10 +150,9 @@ class ClpArchiveDecoder implements Decoder { throw new Error("Log event at index ${logEventIdx} does not exist"); } - const message: string = toMessage(logEvent, textDecoder); const logLevel: LOG_LEVEL = logEvent.logLevel; const timestamp: bigint = logEvent.timestamp; - + const message: string = toMessage(logEvent, textDecoder); results.push([message, Number(timestamp), logLevel, logEventIdx + 1]); } diff --git a/new-log-viewer/src/services/decoders/ClpArchiveDecoder/logevent.ts b/new-log-viewer/src/services/decoders/ClpArchiveDecoder/logevent.ts index edf5fee3..63a5463c 100644 --- a/new-log-viewer/src/services/decoders/ClpArchiveDecoder/logevent.ts +++ b/new-log-viewer/src/services/decoders/ClpArchiveDecoder/logevent.ts @@ -7,7 +7,7 @@ import {Placeholder} from "../../../typings/placeholder"; dayjs.extend(bigIntSupport); /** - * IR-like logEvent retrieved from CLP archive. + * IR-like log event retrieved from CLP archive. */ interface ArchiveLogEvent { timestamp: bigint; diff --git a/new-log-viewer/src/services/decoders/ClpArchiveDecoder/metadata.ts b/new-log-viewer/src/services/decoders/ClpArchiveDecoder/metadata.ts index 35bf88b0..207a267b 100644 --- a/new-log-viewer/src/services/decoders/ClpArchiveDecoder/metadata.ts +++ b/new-log-viewer/src/services/decoders/ClpArchiveDecoder/metadata.ts @@ -14,7 +14,7 @@ type SegmentFileSizes = number[]; * Byte sizes for non-segment archive files. */ interface NonSegmentFileSizes { - metadataDB: number; + metadataDb: number; logTypeDict: number; logTypeSegIndex: number; varDict: number; @@ -22,7 +22,7 @@ interface NonSegmentFileSizes { } /** - * Segment Metadata. + * Segment metadata. */ interface SegmentInfo { numMessages: number; @@ -72,28 +72,28 @@ const deserializeHeaderMetadata = ( }; /** - * Parse single file archive metadata to retrieve byte sizes of all files - * in the archive. The sizes are needed to accurately decode individual files. + * Parse header metadata to retrieve byte sizes of all files in the archive. + * The sizes are needed to accurately decode individual files. * - * @param singleFileArchiveMetadata Metadata containing archived file sizes. + * @param headerMetadata Metadata containing archived file sizes. * @return Array with two elements. First element contains sizes of non-segment * files. Second element contains the size for each segment. */ const parseHeaderMetadata = ( // eslint-disable-next-line @typescript-eslint/no-explicit-any - singleFileArchiveMetadata: any + headerMetadata: any ): [NonSegmentFileSizes, SegmentFileSizes] => { - if (!singleFileArchiveMetadata.archive_files) { + if (!headerMetadata.archive_files) { throw new Error("Archive file metadata not found"); } // Array of files in the archive each containing a name (fileInfo.n) and an // offset (fileInfo.o). - const fileInfos = singleFileArchiveMetadata.archive_files; + const fileInfos = headerMetadata.archive_files; // Create null instances to fill in afterwards. const nonSegmentSizes: NonSegmentFileSizes = { - metadataDB: 0, + metadataDb: 0, logTypeDict: 0, logTypeSegIndex: 0, varDict: 0, @@ -114,7 +114,7 @@ const parseHeaderMetadata = ( if (false === isSegment(name)) { switch (name) { case "metadata.db": - nonSegmentSizes.metadataDB = size; + nonSegmentSizes.metadataDb = size; break; case "logtype.dict": nonSegmentSizes.logTypeDict = size; @@ -155,19 +155,19 @@ const isSegment = (name: string) => { * * @param dataInputStream Byte stream containing single file archive with * offset at start of database. - * @param metadataDBsize Byte size of database. + * @param metadataDbSize Byte size of database. * @return Array containing metadata for each segment. */ const querySegmentInfos = async ( dataInputStream: DataInputStream, - metadataDBsize: number + metadataDbSize: number ): Promise => { // Required to load the sqljs wasm binary asynchronously. const SQL: initSqlJs.SqlJsStatic = await initSqlJs({ locateFile: (file) => `static/js/${file}`, }); - const dbBytes: Uint8Array = dataInputStream.readFully(metadataDBsize); + const dbBytes: Uint8Array = dataInputStream.readFully(metadataDbSize); const db = new SQL.Database(dbBytes); const queryResult: initSqlJs.QueryExecResult[] = db.exec(` diff --git a/new-log-viewer/src/services/decoders/ClpArchiveDecoder/segment.ts b/new-log-viewer/src/services/decoders/ClpArchiveDecoder/segment.ts index bc5e635a..3212a0f9 100644 --- a/new-log-viewer/src/services/decoders/ClpArchiveDecoder/segment.ts +++ b/new-log-viewer/src/services/decoders/ClpArchiveDecoder/segment.ts @@ -22,7 +22,7 @@ interface Segment { * @param dataInputStream Byte stream containing single file archive with offset * at start of segments. * @param segmentSize Array of byte sizes for each segment in archive. - * @param segmentInfos Byte sizes for non-segment archive files. + * @param segmentInfos Segment metadata. * @param logTypeDict Archive log type dictionary. * @param varDict Archive variable dictionary. * @return Array with combined log events from all segments. @@ -36,16 +36,16 @@ const deserializeSegments = async ( ): Promise => { const logEvents: ArchiveLogEvent[] = []; for (let index = 0; index < segmentSizes.length; index++) { - const size: number | undefined = segmentSizes[index]; + const segmentSize: number | undefined = segmentSizes[index]; const segmentInfo: SegmentInfo | undefined = segmentInfos[index]; - if (!size || !segmentInfo) { + if (!segmentSize || !segmentInfo) { throw new Error("Segment metadata was not found"); } const segment: Segment = await deserializeSegment( dataInputStream, - size, + segmentSize, segmentInfo ); @@ -155,19 +155,20 @@ const toLogEvents = ( /** * Retrieves dictionary and encoded variables for a specific log message. - * Traverses log type until a variable placeholder is found. For each - * variable placeholder found, a value is popped from the segment variables array. - * Dictionary and encoded variables are distinguished by different byte - * placeholders. If the variable is a dictionary variable, the value is used - * to index into the archive's variable dictionary, and the lookup result is - * added to its array. If the variable is an encoded variable, the value is simply - * added to its array. The function returns two arrays. First for dictionary - * variables, and second for encoded variables. + * The function returns two arrays; The first for dictionary variables, + * and the second for encoded variables. Traverses log type until a variable + * placeholder is found. For each variable placeholder found, a value is + * popped from the segment variables array. Dictionary and encoded variables + * are distinguished by different byte placeholders. If the variable is a + * dictionary variable, the value is used to index into the archive's variable + * dictionary, and the lookup result is added to dictionary array. If the variable is + * an encoded variable, the value is simply added to encoded array. * * @param logType Log with placeholders for variables. * @param segmentVarIterator Iterator for segment variables. * @param varDict Archive variable dictionary. - * @return Two arrays, the first for dictionary variables and the second for encoded variables. + * @return Two arrays, the first for dictionary variables and the second for + * encoded variables. */ const getLogEventVariables = ( logType: Uint8Array,