mirror of
https://github.com/jwetzell/psn-js.git
synced 2026-09-08 15:59:22 +00:00
align structure more with underlying chunk layout
This commit is contained in:
@@ -1,37 +1,37 @@
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { InfoPacketChunk } from '../../models/info/info-packet-chunk';
|
||||
import { InfoPacketChunk, InfoPacketChunkData } from '../../models/info/info-packet-chunk';
|
||||
|
||||
function decodeInfoPacketChunk(infoPacketChunk: InfoPacketChunk) {
|
||||
if (infoPacketChunk.has_subchunks && infoPacketChunk.chunk_data && infoPacketChunk.data_len) {
|
||||
export default (buffer: Uint8Array): InfoPacketChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const data: InfoPacketChunkData = {};
|
||||
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < infoPacketChunk.data_len) {
|
||||
const view = new DataView(
|
||||
infoPacketChunk.chunk_data.buffer,
|
||||
infoPacketChunk.chunk_data.byteOffset,
|
||||
infoPacketChunk.chunk_data.byteLength
|
||||
);
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength);
|
||||
const chunkId = view.getUint16(offset, true);
|
||||
switch (chunkId) {
|
||||
case 0x0000:
|
||||
infoPacketChunk.packet_header = Decoders.PacketHeaderChunk(infoPacketChunk.chunk_data.slice(offset));
|
||||
data.packetHeader = Decoders.PacketHeaderChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (infoPacketChunk.packet_header?.data_len) {
|
||||
offset += infoPacketChunk.packet_header.data_len;
|
||||
if (data.packetHeader?.chunk.header.dataLen) {
|
||||
offset += data.packetHeader.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
case 0x0001:
|
||||
infoPacketChunk.system_name = Decoders.InfoSystemNameChunk(infoPacketChunk.chunk_data.slice(offset));
|
||||
data.systemName = Decoders.InfoSystemNameChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (infoPacketChunk.system_name?.data_len) {
|
||||
offset += infoPacketChunk.system_name.data_len;
|
||||
if (data.systemName?.chunk.header.dataLen) {
|
||||
offset += data.systemName?.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
case 0x0002:
|
||||
infoPacketChunk.tracker_list = Decoders.InfoTrackerListChunk(infoPacketChunk.chunk_data.slice(offset));
|
||||
data.trackerList = Decoders.InfoTrackerListChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (infoPacketChunk.tracker_list?.data_len) {
|
||||
offset += infoPacketChunk.tracker_list.data_len;
|
||||
if (data.trackerList?.chunk.header.dataLen) {
|
||||
offset += data.trackerList.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@@ -39,7 +39,9 @@ function decodeInfoPacketChunk(infoPacketChunk: InfoPacketChunk) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default (buffer: Uint8Array): InfoPacketChunk =>
|
||||
Decoders.Chunk(buffer, decodeInfoPacketChunk) as InfoPacketChunk;
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
import { Decoders } from '..';
|
||||
import { InfoSystemNameChunk } from '../../models/info/info-system-name-chunk';
|
||||
import { InfoSystemNameChunk, InfoSystemNameChunkData } from '../../models/info/info-system-name-chunk';
|
||||
|
||||
function decodeSystemNameChunk(systemNameChunk: InfoSystemNameChunk) {
|
||||
if (systemNameChunk.chunk_data !== undefined && systemNameChunk.data_len !== undefined) {
|
||||
systemNameChunk.system_name = new TextDecoder().decode(
|
||||
systemNameChunk.chunk_data.slice(0, systemNameChunk.data_len)
|
||||
);
|
||||
}
|
||||
}
|
||||
export default (buffer: Uint8Array): InfoSystemNameChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
export default (buffer: Uint8Array): InfoSystemNameChunk =>
|
||||
Decoders.Chunk(buffer, decodeSystemNameChunk) as InfoSystemNameChunk;
|
||||
const data: InfoSystemNameChunkData = {
|
||||
systemName: new TextDecoder().decode(chunk.chunkData.subarray(0, chunk.header.dataLen)),
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,31 +1,36 @@
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { InfoTrackerChunk } from '../../models/info/info-tracker-chunk';
|
||||
import { InfoTrackerChunk, InfoTrackerChunkData } from '../../models/info/info-tracker-chunk';
|
||||
|
||||
function decodeInfoTrackerChunk(infoTrackerChunk: InfoTrackerChunk) {
|
||||
if (infoTrackerChunk.has_subchunks && infoTrackerChunk.chunk_data && infoTrackerChunk.data_len) {
|
||||
export default (buffer: Uint8Array): InfoTrackerChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData && chunk.header.dataLen) {
|
||||
let offset = 0;
|
||||
while (offset < infoTrackerChunk.data_len) {
|
||||
const view = new DataView(
|
||||
infoTrackerChunk.chunk_data.buffer,
|
||||
infoTrackerChunk.chunk_data.byteOffset,
|
||||
infoTrackerChunk.chunk_data.byteLength
|
||||
);
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const view = new DataView(chunk.chunkData.buffer, chunk.chunkData.byteOffset, chunk.chunkData.byteLength);
|
||||
const chunkId = view.getUint16(offset, true);
|
||||
switch (chunkId) {
|
||||
case 0x0000:
|
||||
infoTrackerChunk.tracker_name = Decoders.InfoTrackerNameChunk(infoTrackerChunk.chunk_data.slice(offset));
|
||||
const data: InfoTrackerChunkData = {
|
||||
trackerName: Decoders.InfoTrackerNameChunk(chunk.chunkData.subarray(offset)),
|
||||
};
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (infoTrackerChunk.tracker_name?.data_len) {
|
||||
offset += infoTrackerChunk?.tracker_name?.data_len;
|
||||
if (data.trackerName.chunk.header.dataLen) {
|
||||
offset += data.trackerName.chunk.header.dataLen;
|
||||
}
|
||||
break;
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default (buffer: Uint8Array): InfoTrackerChunk => Decoders.Chunk(buffer, decodeInfoTrackerChunk);
|
||||
return {
|
||||
chunk,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,24 +1,33 @@
|
||||
import { Decoders } from '..';
|
||||
import { Constants } from '../../constants';
|
||||
import { InfoTrackerListChunk } from '../../models/info/info-tracker-list-chunk';
|
||||
import { InfoTrackerChunk } from '../../models/info/info-tracker-chunk';
|
||||
import { InfoTrackerListChunk, InfoTrackerListChunkData } from '../../models/info/info-tracker-list-chunk';
|
||||
|
||||
function decodeInfoTrackerListChunk(infoTrackerListChunk: InfoTrackerListChunk) {
|
||||
infoTrackerListChunk.trackers = {};
|
||||
if (infoTrackerListChunk.has_subchunks && infoTrackerListChunk.chunk_data) {
|
||||
export default (buffer: Uint8Array): InfoTrackerListChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const trackers: InfoTrackerChunk[] = [];
|
||||
|
||||
if (chunk.header.hasSubchunks && chunk.chunkData) {
|
||||
let offset = 0;
|
||||
if (infoTrackerListChunk.data_len) {
|
||||
while (offset < infoTrackerListChunk.data_len) {
|
||||
const trackerChunk = Decoders.InfoTrackerChunk(infoTrackerListChunk.chunk_data.slice(offset));
|
||||
if (chunk.header.dataLen) {
|
||||
while (offset < chunk.header.dataLen) {
|
||||
const trackerChunk = Decoders.InfoTrackerChunk(chunk.chunkData.subarray(offset));
|
||||
offset += Constants.CHUNK_HEADER_SIZE;
|
||||
if (trackerChunk.data_len) {
|
||||
offset += trackerChunk.data_len;
|
||||
if (trackerChunk.chunk.header.dataLen) {
|
||||
offset += trackerChunk.chunk.header.dataLen;
|
||||
}
|
||||
if (trackerChunk.id !== undefined) {
|
||||
infoTrackerListChunk.trackers[trackerChunk.id] = trackerChunk;
|
||||
if (trackerChunk.chunk.header.id !== undefined) {
|
||||
trackers.push(trackerChunk);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
export default (buffer: Uint8Array): InfoTrackerListChunk =>
|
||||
Decoders.Chunk(buffer, decodeInfoTrackerListChunk) as InfoTrackerListChunk;
|
||||
const data: InfoTrackerListChunkData = {
|
||||
trackers,
|
||||
};
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import { Decoders } from '..';
|
||||
import { InfoTrackerNameChunk } from '../../models/info/info-tracker-name-chunk';
|
||||
import { InfoTrackerNameChunk, InfoTrackerNameChunkData } from '../../models/info/info-tracker-name-chunk';
|
||||
|
||||
function decodeTrackerNameChunk(trackerNameChunk: InfoTrackerNameChunk) {
|
||||
if (trackerNameChunk.chunk_data !== undefined && trackerNameChunk.data_len !== undefined) {
|
||||
trackerNameChunk.tracker_name = new TextDecoder().decode(
|
||||
trackerNameChunk.chunk_data.slice(0, trackerNameChunk.data_len)
|
||||
);
|
||||
}
|
||||
}
|
||||
export default (buffer: Uint8Array): InfoTrackerNameChunk =>
|
||||
Decoders.Chunk(buffer, decodeTrackerNameChunk) as InfoTrackerNameChunk;
|
||||
export default (buffer: Uint8Array): InfoTrackerNameChunk => {
|
||||
const chunk = Decoders.Chunk(buffer);
|
||||
|
||||
const data: InfoTrackerNameChunkData = {
|
||||
trackerName: new TextDecoder().decode(chunk.chunkData.subarray(0, chunk.header.dataLen)),
|
||||
};
|
||||
|
||||
return {
|
||||
chunk,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user