90 lines
2.5 KiB
TypeScript
90 lines
2.5 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 NameValuePairMessage implements MessageBase
|
|
{
|
|
name = 'NameValuePair';
|
|
messageFlags = MessageFlags.Trusted | MessageFlags.FrequencyLow;
|
|
id = Message.NameValuePair;
|
|
|
|
TaskData: {
|
|
ID: UUID;
|
|
};
|
|
NameValueData: {
|
|
NVPair: Buffer;
|
|
}[];
|
|
|
|
getSize(): number
|
|
{
|
|
return this.calculateVarVarSize(this.NameValueData, 'NVPair', 2) + 17;
|
|
}
|
|
|
|
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.TaskData['ID'].writeToBuffer(buf, pos);
|
|
pos += 16;
|
|
const count = this.NameValueData.length;
|
|
buf.writeUInt8(this.NameValueData.length, pos++);
|
|
for (let i = 0; i < count; i++)
|
|
{
|
|
buf.writeUInt16LE(this.NameValueData[i]['NVPair'].length, pos);
|
|
pos += 2;
|
|
this.NameValueData[i]['NVPair'].copy(buf, pos);
|
|
pos += this.NameValueData[i]['NVPair'].length;
|
|
}
|
|
return pos - startPos;
|
|
}
|
|
|
|
// @ts-ignore
|
|
readFromBuffer(buf: Buffer, pos: number): number
|
|
{
|
|
const startPos = pos;
|
|
let varLength = 0;
|
|
const newObjTaskData: {
|
|
ID: UUID
|
|
} = {
|
|
ID: UUID.zero()
|
|
};
|
|
newObjTaskData['ID'] = new UUID(buf, pos);
|
|
pos += 16;
|
|
this.TaskData = newObjTaskData;
|
|
if (pos >= buf.length)
|
|
{
|
|
return pos - startPos;
|
|
}
|
|
const count = buf.readUInt8(pos++);
|
|
this.NameValueData = [];
|
|
for (let i = 0; i < count; i++)
|
|
{
|
|
const newObjNameValueData: {
|
|
NVPair: Buffer
|
|
} = {
|
|
NVPair: Buffer.allocUnsafe(0)
|
|
};
|
|
varLength = buf.readUInt16LE(pos);
|
|
pos += 2;
|
|
newObjNameValueData['NVPair'] = buf.slice(pos, pos + varLength);
|
|
pos += varLength;
|
|
this.NameValueData.push(newObjNameValueData);
|
|
}
|
|
return pos - startPos;
|
|
}
|
|
}
|
|
|