Skip to content

Instantly share code, notes, and snippets.

@daniellandau
Created April 5, 2019 06:59
Show Gist options
  • Save daniellandau/01d494a835741198a64232297b0fbd03 to your computer and use it in GitHub Desktop.
Save daniellandau/01d494a835741198a64232297b0fbd03 to your computer and use it in GitHub Desktop.
const fs = require("fs")
const buf = fs.readFileSync("/dev/stdin")
if (buf.length !== 20) {
console.log(`${+new Date()};error;error;error`)
process.exit()
}
const offset = 8
const dataByteSize = 12
const dataSize = dataByteSize / 4
const arbuf = new ArrayBuffer(dataByteSize)
const intView = new Int32Array(arbuf)
const floatView = new Float32Array(arbuf)
for (let i = 0; i < dataSize; ++i) {
intView[i] =
buf[offset + i * 4 + 0] << 24 |
buf[offset + i * 4 + 1] << 16 |
buf[offset + i * 4 + 2] << 8 |
buf[offset + i * 4 + 3] << 0
}
let result = ""
result += +new Date()
for (let i = 0; i < dataSize; ++i) {
result += `;${floatView[i]}`
}
console.log(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment