126 lines
3.9 KiB
TypeScript
126 lines
3.9 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 AlertMessageMessage implements MessageBase
|
|
{
|
|
name = 'AlertMessage';
|
|
messageFlags = MessageFlags.Trusted | MessageFlags.FrequencyLow;
|
|
id = Message.AlertMessage;
|
|
|
|
AlertData: {
|
|
Message: Buffer;
|
|
};
|
|
AlertInfo: {
|
|
Message: Buffer;
|
|
ExtraParams: Buffer;
|
|
}[];
|
|
AgentInfo: {
|
|
AgentID: UUID;
|
|
}[];
|
|
|
|
getSize(): number
|
|
{
|
|
return (this.AlertData['Message'].length + 1) + this.calculateVarVarSize(this.AlertInfo, 'Message', 1) + this.calculateVarVarSize(this.AlertInfo, 'ExtraParams', 1) + ((16) * this.AgentInfo.length) + 2;
|
|
}
|
|
|
|
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;
|
|
buf.writeUInt8(this.AlertData['Message'].length, pos++);
|
|
this.AlertData['Message'].copy(buf, pos);
|
|
pos += this.AlertData['Message'].length;
|
|
let count = this.AlertInfo.length;
|
|
buf.writeUInt8(this.AlertInfo.length, pos++);
|
|
for (let i = 0; i < count; i++)
|
|
{
|
|
buf.writeUInt8(this.AlertInfo[i]['Message'].length, pos++);
|
|
this.AlertInfo[i]['Message'].copy(buf, pos);
|
|
pos += this.AlertInfo[i]['Message'].length;
|
|
buf.writeUInt8(this.AlertInfo[i]['ExtraParams'].length, pos++);
|
|
this.AlertInfo[i]['ExtraParams'].copy(buf, pos);
|
|
pos += this.AlertInfo[i]['ExtraParams'].length;
|
|
}
|
|
count = this.AgentInfo.length;
|
|
buf.writeUInt8(this.AgentInfo.length, pos++);
|
|
for (let i = 0; i < count; i++)
|
|
{
|
|
this.AgentInfo[i]['AgentID'].writeToBuffer(buf, pos);
|
|
pos += 16;
|
|
}
|
|
return pos - startPos;
|
|
}
|
|
|
|
// @ts-ignore
|
|
readFromBuffer(buf: Buffer, pos: number): number
|
|
{
|
|
const startPos = pos;
|
|
let varLength = 0;
|
|
const newObjAlertData: {
|
|
Message: Buffer
|
|
} = {
|
|
Message: Buffer.allocUnsafe(0)
|
|
};
|
|
varLength = buf.readUInt8(pos++);
|
|
newObjAlertData['Message'] = buf.slice(pos, pos + varLength);
|
|
pos += varLength;
|
|
this.AlertData = newObjAlertData;
|
|
if (pos >= buf.length)
|
|
{
|
|
return pos - startPos;
|
|
}
|
|
let count = buf.readUInt8(pos++);
|
|
this.AlertInfo = [];
|
|
for (let i = 0; i < count; i++)
|
|
{
|
|
const newObjAlertInfo: {
|
|
Message: Buffer,
|
|
ExtraParams: Buffer
|
|
} = {
|
|
Message: Buffer.allocUnsafe(0),
|
|
ExtraParams: Buffer.allocUnsafe(0)
|
|
};
|
|
varLength = buf.readUInt8(pos++);
|
|
newObjAlertInfo['Message'] = buf.slice(pos, pos + varLength);
|
|
pos += varLength;
|
|
varLength = buf.readUInt8(pos++);
|
|
newObjAlertInfo['ExtraParams'] = buf.slice(pos, pos + varLength);
|
|
pos += varLength;
|
|
this.AlertInfo.push(newObjAlertInfo);
|
|
}
|
|
if (pos >= buf.length)
|
|
{
|
|
return pos - startPos;
|
|
}
|
|
count = buf.readUInt8(pos++);
|
|
this.AgentInfo = [];
|
|
for (let i = 0; i < count; i++)
|
|
{
|
|
const newObjAgentInfo: {
|
|
AgentID: UUID
|
|
} = {
|
|
AgentID: UUID.zero()
|
|
};
|
|
newObjAgentInfo['AgentID'] = new UUID(buf, pos);
|
|
pos += 16;
|
|
this.AgentInfo.push(newObjAgentInfo);
|
|
}
|
|
return pos - startPos;
|
|
}
|
|
}
|
|
|