mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-08-15 04:13:51 +00:00
reuse fixed size DataViews
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
const header = new DataView(new ArrayBuffer(4));
|
||||
export default (id: number, chunkData: Uint8Array, hasSubchunks: boolean): Uint8Array => {
|
||||
if (!Number.isInteger(id)) {
|
||||
throw new Error('chunk id must be an integer');
|
||||
@@ -11,7 +12,6 @@ export default (id: number, chunkData: Uint8Array, hasSubchunks: boolean): Uint8
|
||||
throw new Error('chunkData can not be greater than 32767 bytes');
|
||||
}
|
||||
|
||||
const header = new DataView(new ArrayBuffer(4));
|
||||
header.setUint16(0, id, true);
|
||||
const hasSubChunksBit = (hasSubchunks ? 1 : 0) << 15;
|
||||
header.setUint16(2, hasSubChunksBit + chunkData.length, true);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import chunk from '../chunk';
|
||||
|
||||
const buf = new DataView(new ArrayBuffer(8));
|
||||
export default (timestamp: bigint): Uint8Array => {
|
||||
const buf = new DataView(new ArrayBuffer(8));
|
||||
buf.setBigUint64(0, BigInt(timestamp), true);
|
||||
return chunk(0x0006, new Uint8Array(buf.buffer), false);
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import chunk from './chunk';
|
||||
|
||||
const packetHeader = new DataView(new ArrayBuffer(12));
|
||||
export default (
|
||||
timestamp: bigint,
|
||||
versionHigh: number,
|
||||
@@ -33,7 +34,6 @@ export default (
|
||||
throw new Error('frame packet count must be >= 0 and <= 255');
|
||||
}
|
||||
|
||||
const packetHeader = new DataView(new ArrayBuffer(12));
|
||||
packetHeader.setBigUint64(0, BigInt(timestamp), true);
|
||||
packetHeader.setUint8(8, versionHigh);
|
||||
packetHeader.setUint8(9, versionLow);
|
||||
|
||||
Reference in New Issue
Block a user