Files
node-metaverse/lib/classes/messages/GroupNoticesListReply.ts

132 lines
4.2 KiB
TypeScript

// This file has been automatically generated by writeMessageClasses.js
import { UUID } from '../UUID';
import { MessageFlags } from '../../enums/MessageFlags';
import { MessageBase } from '../MessageBase';
import { Message } from '../../enums/Message';
export class GroupNoticesListReplyMessage implements MessageBase
{
name = 'GroupNoticesListReply';
messageFlags = MessageFlags.Trusted | MessageFlags.FrequencyLow;
id = Message.GroupNoticesListReply;
AgentData: {
AgentID: UUID;
GroupID: UUID;
};
Data: {
NoticeID: UUID;
Timestamp: number;
FromName: Buffer;
Subject: Buffer;
HasAttachment: boolean;
AssetType: number;
}[];
getSize(): number
{
return this.calculateVarVarSize(this.Data, 'FromName', 2) + this.calculateVarVarSize(this.Data, 'Subject', 2) + ((22) * this.Data.length) + 33;
}
calculateVarVarSize(block: {[key: string]: any}[], paramName: string, extraPerVar: number): number
{
let size = 0;
for (const bl of block)
{
size += bl[paramName].length + extraPerVar;
}
return size;
}
// @ts-ignore
writeToBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
this.AgentData['AgentID'].writeToBuffer(buf, pos);
pos += 16;
this.AgentData['GroupID'].writeToBuffer(buf, pos);
pos += 16;
const count = this.Data.length;
buf.writeUInt8(this.Data.length, pos++);
for (let i = 0; i < count; i++)
{
this.Data[i]['NoticeID'].writeToBuffer(buf, pos);
pos += 16;
buf.writeUInt32LE(this.Data[i]['Timestamp'], pos);
pos += 4;
buf.writeUInt16LE(this.Data[i]['FromName'].length, pos);
pos += 2;
this.Data[i]['FromName'].copy(buf, pos);
pos += this.Data[i]['FromName'].length;
buf.writeUInt16LE(this.Data[i]['Subject'].length, pos);
pos += 2;
this.Data[i]['Subject'].copy(buf, pos);
pos += this.Data[i]['Subject'].length;
buf.writeUInt8((this.Data[i]['HasAttachment']) ? 1 : 0, pos++);
buf.writeUInt8(this.Data[i]['AssetType'], pos++);
}
return pos - startPos;
}
// @ts-ignore
readFromBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
let varLength = 0;
const newObjAgentData: {
AgentID: UUID,
GroupID: UUID
} = {
AgentID: UUID.zero(),
GroupID: UUID.zero()
};
newObjAgentData['AgentID'] = new UUID(buf, pos);
pos += 16;
newObjAgentData['GroupID'] = new UUID(buf, pos);
pos += 16;
this.AgentData = newObjAgentData;
if (pos >= buf.length)
{
return pos - startPos;
}
const count = buf.readUInt8(pos++);
this.Data = [];
for (let i = 0; i < count; i++)
{
const newObjData: {
NoticeID: UUID,
Timestamp: number,
FromName: Buffer,
Subject: Buffer,
HasAttachment: boolean,
AssetType: number
} = {
NoticeID: UUID.zero(),
Timestamp: 0,
FromName: Buffer.allocUnsafe(0),
Subject: Buffer.allocUnsafe(0),
HasAttachment: false,
AssetType: 0
};
newObjData['NoticeID'] = new UUID(buf, pos);
pos += 16;
newObjData['Timestamp'] = buf.readUInt32LE(pos);
pos += 4;
varLength = buf.readUInt16LE(pos);
pos += 2;
newObjData['FromName'] = buf.slice(pos, pos + varLength);
pos += varLength;
varLength = buf.readUInt16LE(pos);
pos += 2;
newObjData['Subject'] = buf.slice(pos, pos + varLength);
pos += varLength;
newObjData['HasAttachment'] = (buf.readUInt8(pos++) === 1);
newObjData['AssetType'] = buf.readUInt8(pos++);
this.Data.push(newObjData);
}
return pos - startPos;
}
}