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

105 lines
3.1 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 DirPopularReplyPacket implements Packet
{
name = 'DirPopularReply';
flags = MessageFlags.Trusted | MessageFlags.Zerocoded | MessageFlags.Deprecated | MessageFlags.FrequencyLow;
id = 4294901813;
AgentData: {
AgentID: UUID;
};
QueryData: {
QueryID: UUID;
};
QueryReplies: {
ParcelID: UUID;
Name: string;
Dwell: number;
}[];
getSize(): number
{
return ((this.calculateVarVarSize(this.QueryReplies, 'Name', 1) + 20) * this.QueryReplies.length) + 33;
}
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;
this.AgentData['AgentID'].writeToBuffer(buf, pos);
pos += 16;
this.QueryData['QueryID'].writeToBuffer(buf, pos);
pos += 16;
const count = this.QueryReplies.length;
buf.writeUInt8(this.QueryReplies.length, pos++);
for (let i = 0; i < count; i++)
{
this.QueryReplies[i]['ParcelID'].writeToBuffer(buf, pos);
pos += 16;
buf.write(this.QueryReplies[i]['Name'], pos);
pos += this.QueryReplies[i]['Name'].length;
buf.writeFloatLE(this.QueryReplies[i]['Dwell'], pos);
pos += 4;
}
return pos - startPos;
}
readFromBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
const newObjAgentData: {
AgentID: UUID
} = {
AgentID: UUID.zero()
};
newObjAgentData['AgentID'] = new UUID(buf, pos);
pos += 16;
this.AgentData = newObjAgentData;
const newObjQueryData: {
QueryID: UUID
} = {
QueryID: UUID.zero()
};
newObjQueryData['QueryID'] = new UUID(buf, pos);
pos += 16;
this.QueryData = newObjQueryData;
const count = buf.readUInt8(pos++);
this.QueryReplies = [];
for (let i = 0; i < count; i++)
{
const newObjQueryReplies: {
ParcelID: UUID,
Name: string,
Dwell: number
} = {
ParcelID: UUID.zero(),
Name: '',
Dwell: 0
};
newObjQueryReplies['ParcelID'] = new UUID(buf, pos);
pos += 16;
newObjQueryReplies['Name'] = buf.toString('utf8', pos, length);
pos += length;
newObjQueryReplies['Dwell'] = buf.readFloatLE(pos);
pos += 4;
this.QueryReplies.push(newObjQueryReplies);
}
return pos - startPos;
}
}