mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-08-09 17:33:50 +00:00
add a little bit of error catching
This commit is contained in:
@@ -1,11 +1,15 @@
|
||||
const chunk = require('./chunk');
|
||||
|
||||
module.exports = (timestamp, versionHigh, versionLow, frameId, framePacketCount) => {
|
||||
if (frameId > 255) {
|
||||
throw new Error('frame id must be >= 0 and <= 255');
|
||||
}
|
||||
const packetHeader = Buffer.alloc(12);
|
||||
const timestampHigh = timestamp.toString(2).padStart(64, '0').substring(0, 32);
|
||||
const timestampLow = timestamp.toString(2).padStart(64, '0').substring(32);
|
||||
packetHeader.writeUInt32LE(parseInt(timestampLow, 2));
|
||||
packetHeader.writeUInt32LE(parseInt(timestampHigh, 2), 4);
|
||||
|
||||
packetHeader.writeUint8(versionHigh, 8);
|
||||
packetHeader.writeUint8(versionLow, 9);
|
||||
packetHeader.writeUint8(frameId, 10);
|
||||
|
||||
Reference in New Issue
Block a user