Latest packet handling, parsing, enums, generators, etc..

This commit is contained in:
Casper Warden
2017-11-24 17:45:34 +00:00
parent ec300e33ac
commit 261f28698a
496 changed files with 30448 additions and 57 deletions

View File

@@ -26,4 +26,58 @@ export class RequestXferPacket implements Packet
return (this.XferID['Filename'].length + 1) + 29;
}
writeToBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
buf.writeInt32LE(this.XferID['ID'].low, pos);
pos += 4;
buf.writeInt32LE(this.XferID['ID'].high, pos);
pos += 4;
buf.write(this.XferID['Filename'], pos);
pos += this.XferID['Filename'].length;
buf.writeUInt8(this.XferID['FilePath'], pos++);
buf.writeUInt8((this.XferID['DeleteOnCompletion']) ? 1 : 0, pos++);
buf.writeUInt8((this.XferID['UseBigPackets']) ? 1 : 0, pos++);
this.XferID['VFileID'].writeToBuffer(buf, pos);
pos += 16;
buf.writeInt16LE(this.XferID['VFileType'], pos);
pos += 2;
return pos - startPos;
}
readFromBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
const newObjXferID: {
ID: Long,
Filename: string,
FilePath: number,
DeleteOnCompletion: boolean,
UseBigPackets: boolean,
VFileID: UUID,
VFileType: number
} = {
ID: Long.ZERO,
Filename: '',
FilePath: 0,
DeleteOnCompletion: false,
UseBigPackets: false,
VFileID: UUID.zero(),
VFileType: 0
};
newObjXferID['ID'] = new Long(buf.readInt32LE(pos), buf.readInt32LE(pos+4));
pos += 8;
newObjXferID['Filename'] = buf.toString('utf8', pos, length);
pos += length;
newObjXferID['FilePath'] = buf.readUInt8(pos++);
newObjXferID['DeleteOnCompletion'] = (buf.readUInt8(pos++) === 1);
newObjXferID['UseBigPackets'] = (buf.readUInt8(pos++) === 1);
newObjXferID['VFileID'] = new UUID(buf, pos);
pos += 16;
newObjXferID['VFileType'] = buf.readInt16LE(pos);
pos += 2;
this.XferID = newObjXferID;
return pos - startPos;
}
}