Skip to content

Commit

Permalink
check if data types are correct
Browse files Browse the repository at this point in the history
  • Loading branch information
twitchyvr committed Nov 19, 2023
1 parent 9c87f9a commit ad87553
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ module.exports = async function (context, req) {
uniqueId: telemetry.uniqueId(),
header: telemetry.headers, // Assuming this contains the parsed header data
sessionInfo: telemetry.sessionInfo, // Contains the parsed YAML session info
varHeaders: telemetry.varHeaders(), // Assuming this method returns the variable headers
// Add a method to extract summarized telemetry data
varHeaders: telemetry.varHeaders, // Assuming this method returns the variable headers
telemetryData: telemetry.getTelemetryDataSummary()
// You can add more methods as needed to extract different parts of the telemetry data
}

// Response
Expand Down
26 changes: 19 additions & 7 deletions src/utils/telemetry-file-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ const { SIZE_IN_BYTES: VAR_HEADER_SIZE_IN_BYTES, VarHeader } = require('../heade
const readFileToBuffer = require('../utils/read-file-to-buffer')
const Telemetry = require('../telemetry')

// Utility function to log and check if a value is a number
function isNumber (value, name) {
if (typeof value !== 'number' || isNaN(value)) {
console.error(`${name} is not a number. Received:`, value)
return false
}
return true
}

const openDataFile = dataFile => new Promise((resolve, reject) => {
fs.open(dataFile, 'r', (err, fd) => {
err ? reject(err) : resolve(fd)
Expand All @@ -22,20 +31,23 @@ const diskSubHeaderFromFileDescriptor = fd =>
readFileToBuffer(fd, DISK_SUB_HEADER_SIZE_IN_BYTES, HEADER_SIZE_IN_BYTES)
.then(DiskSubHeader.fromBuffer)

/**
const sessionInfoStringFromFileDescriptor = (fd, telemetryHeader) =>
readFileToBuffer(fd, telemetryHeader.sessionInfoOffset, telemetryHeader.sessionInfoLength)
.then(x => x.toString('ascii'))
*/

const sessionInfoStringFromFileDescriptor = (fd, telemetryHeader) => {
if (!isNumber(telemetryHeader.sessionInfoOffset, 'sessionInfoOffset') ||
!isNumber(telemetryHeader.sessionInfoLength, 'sessionInfoLength')) {
return Promise.reject(new Error('Invalid session info offset or length'))
}

return readFileToBuffer(fd, telemetryHeader.sessionInfoOffset, telemetryHeader.sessionInfoLength)
.then(buffer => {
return buffer.toString('ascii') // encode as ascii
return buffer.toString('ascii')
})
}

const varHeadersFromFileDescriptor = (fd, telemetryHeader) => {
if (!isNumber(telemetryHeader.numVars, 'numVars')) {
return Promise.reject(new Error('Invalid number of variables (numVars)'))
}

const numberOfVariables = telemetryHeader.numVars
const startPosition = telemetryHeader.varHeaderOffset
const fullBufferSize = numberOfVariables * VAR_HEADER_SIZE_IN_BYTES
Expand Down

0 comments on commit ad87553

Please sign in to comment.