Files
node-metaverse/lib/classes/packets/UUIDNameReply.ts

79 lines
2.4 KiB
TypeScript

// This file has been automatically generated by writePacketClasses.js
import {UUID} from '../UUID';
import {MessageFlags} from '../../enums/MessageFlags';
import {Packet} from '../Packet';
export class UUIDNameReplyPacket implements Packet
{
name = 'UUIDNameReply';
flags = MessageFlags.Trusted | MessageFlags.FrequencyLow;
id = 4294901996;
UUIDNameBlock: {
ID: UUID;
FirstName: string;
LastName: string;
}[];
getSize(): number
{
return ((this.calculateVarVarSize(this.UUIDNameBlock, 'FirstName', 1) + this.calculateVarVarSize(this.UUIDNameBlock, 'LastName', 1) + 16) * this.UUIDNameBlock.length) + 1;
}
calculateVarVarSize(block: object[], paramName: string, extraPerVar: number): number
{
let size = 0;
block.forEach((bl: any) =>
{
size += bl[paramName].length + extraPerVar;
});
return size;
}
writeToBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
const count = this.UUIDNameBlock.length;
buf.writeUInt8(this.UUIDNameBlock.length, pos++);
for (let i = 0; i < count; i++)
{
this.UUIDNameBlock[i]['ID'].writeToBuffer(buf, pos);
pos += 16;
buf.write(this.UUIDNameBlock[i]['FirstName'], pos);
pos += this.UUIDNameBlock[i]['FirstName'].length;
buf.write(this.UUIDNameBlock[i]['LastName'], pos);
pos += this.UUIDNameBlock[i]['LastName'].length;
}
return pos - startPos;
}
readFromBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
const count = buf.readUInt8(pos++);
this.UUIDNameBlock = [];
for (let i = 0; i < count; i++)
{
const newObjUUIDNameBlock: {
ID: UUID,
FirstName: string,
LastName: string
} = {
ID: UUID.zero(),
FirstName: '',
LastName: ''
};
newObjUUIDNameBlock['ID'] = new UUID(buf, pos);
pos += 16;
newObjUUIDNameBlock['FirstName'] = buf.toString('utf8', pos, length);
pos += length;
newObjUUIDNameBlock['LastName'] = buf.toString('utf8', pos, length);
pos += length;
this.UUIDNameBlock.push(newObjUUIDNameBlock);
}
return pos - startPos;
}
}