Latest packet handling, parsing, enums, generators, etc..
This commit is contained in:
@@ -24,4 +24,54 @@ export class LoadURLPacket implements Packet
|
||||
return (this.Data['ObjectName'].length + 1 + this.Data['Message'].length + 1 + this.Data['URL'].length + 1) + 33;
|
||||
}
|
||||
|
||||
writeToBuffer(buf: Buffer, pos: number): number
|
||||
{
|
||||
const startPos = pos;
|
||||
buf.write(this.Data['ObjectName'], pos);
|
||||
pos += this.Data['ObjectName'].length;
|
||||
this.Data['ObjectID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
this.Data['OwnerID'].writeToBuffer(buf, pos);
|
||||
pos += 16;
|
||||
buf.writeUInt8((this.Data['OwnerIsGroup']) ? 1 : 0, pos++);
|
||||
buf.write(this.Data['Message'], pos);
|
||||
pos += this.Data['Message'].length;
|
||||
buf.write(this.Data['URL'], pos);
|
||||
pos += this.Data['URL'].length;
|
||||
return pos - startPos;
|
||||
}
|
||||
|
||||
readFromBuffer(buf: Buffer, pos: number): number
|
||||
{
|
||||
const startPos = pos;
|
||||
const newObjData: {
|
||||
ObjectName: string,
|
||||
ObjectID: UUID,
|
||||
OwnerID: UUID,
|
||||
OwnerIsGroup: boolean,
|
||||
Message: string,
|
||||
URL: string
|
||||
} = {
|
||||
ObjectName: '',
|
||||
ObjectID: UUID.zero(),
|
||||
OwnerID: UUID.zero(),
|
||||
OwnerIsGroup: false,
|
||||
Message: '',
|
||||
URL: ''
|
||||
};
|
||||
newObjData['ObjectName'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjData['ObjectID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
newObjData['OwnerID'] = new UUID(buf, pos);
|
||||
pos += 16;
|
||||
newObjData['OwnerIsGroup'] = (buf.readUInt8(pos++) === 1);
|
||||
newObjData['Message'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
newObjData['URL'] = buf.toString('utf8', pos, length);
|
||||
pos += length;
|
||||
this.Data = newObjData;
|
||||
return pos - startPos;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user