mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-08-08 08:53:45 +00:00
add some exception handling
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
export default (id: number, chunkData: Buffer, hasSubchunks: boolean): Buffer => {
|
||||
if (!Number.isInteger(id)) {
|
||||
throw new Error('chunk id must be an integer');
|
||||
}
|
||||
|
||||
if (id > 0xffff || id < 0) {
|
||||
throw new Error('chunk id must be >= 0 and <= 65535');
|
||||
}
|
||||
|
||||
if (chunkData.length > 0x7fff) {
|
||||
throw new Error('chunkData can not be greater than 32767 bytes');
|
||||
}
|
||||
|
||||
@@ -7,9 +7,35 @@ export default (
|
||||
frameId: number,
|
||||
framePacketCount: number
|
||||
): Buffer => {
|
||||
if (frameId > 255) {
|
||||
if (!Number.isInteger(versionHigh)) {
|
||||
throw new Error('version high must be an integer');
|
||||
}
|
||||
if (!Number.isInteger(versionLow)) {
|
||||
throw new Error('version low must be an integer');
|
||||
}
|
||||
if (!Number.isInteger(frameId)) {
|
||||
throw new Error('frame id must be an integer');
|
||||
}
|
||||
if (!Number.isInteger(framePacketCount)) {
|
||||
throw new Error('frame packet count must be an integer');
|
||||
}
|
||||
|
||||
if (versionHigh > 255 || versionHigh < 0) {
|
||||
throw new Error('version high must be >= 0 and <= 255');
|
||||
}
|
||||
|
||||
if (versionLow > 255 || versionLow < 0) {
|
||||
throw new Error('version low must be >= 0 and <= 255');
|
||||
}
|
||||
|
||||
if (frameId > 255 || frameId < 0) {
|
||||
throw new Error('frame id must be >= 0 and <= 255');
|
||||
}
|
||||
|
||||
if (framePacketCount > 255 || framePacketCount < 0) {
|
||||
throw new Error('frame packet count must be >= 0 and <= 255');
|
||||
}
|
||||
|
||||
const packetHeader = Buffer.alloc(12);
|
||||
packetHeader.writeBigUInt64LE(BigInt(timestamp));
|
||||
packetHeader.writeUint8(versionHigh, 8);
|
||||
|
||||
Reference in New Issue
Block a user