92 lines
2.7 KiB
TypeScript
92 lines
2.7 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 SystemMessagePacket implements Packet
|
|
{
|
|
name = 'SystemMessage';
|
|
flags = MessageFlags.Trusted | MessageFlags.Zerocoded | MessageFlags.FrequencyLow;
|
|
id = 4294902164;
|
|
|
|
MethodData: {
|
|
Method: string;
|
|
Invoice: UUID;
|
|
Digest: Buffer;
|
|
};
|
|
ParamList: {
|
|
Parameter: string;
|
|
}[];
|
|
|
|
getSize(): number
|
|
{
|
|
return (this.MethodData['Method'].length + 1) + ((this.calculateVarVarSize(this.ParamList, 'Parameter', 1)) * this.ParamList.length) + 49;
|
|
}
|
|
|
|
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;
|
|
buf.write(this.MethodData['Method'], pos);
|
|
pos += this.MethodData['Method'].length;
|
|
this.MethodData['Invoice'].writeToBuffer(buf, pos);
|
|
pos += 16;
|
|
this.MethodData['Digest'].copy(buf, pos);
|
|
pos += 32;
|
|
const count = this.ParamList.length;
|
|
buf.writeUInt8(this.ParamList.length, pos++);
|
|
for (let i = 0; i < count; i++)
|
|
{
|
|
buf.write(this.ParamList[i]['Parameter'], pos);
|
|
pos += this.ParamList[i]['Parameter'].length;
|
|
}
|
|
return pos - startPos;
|
|
}
|
|
|
|
readFromBuffer(buf: Buffer, pos: number): number
|
|
{
|
|
const startPos = pos;
|
|
const newObjMethodData: {
|
|
Method: string,
|
|
Invoice: UUID,
|
|
Digest: Buffer
|
|
} = {
|
|
Method: '',
|
|
Invoice: UUID.zero(),
|
|
Digest: Buffer.allocUnsafe(0)
|
|
};
|
|
newObjMethodData['Method'] = buf.toString('utf8', pos, length);
|
|
pos += length;
|
|
newObjMethodData['Invoice'] = new UUID(buf, pos);
|
|
pos += 16;
|
|
newObjMethodData['Digest'] = buf.slice(pos, pos + 32);
|
|
pos += 32;
|
|
this.MethodData = newObjMethodData;
|
|
const count = buf.readUInt8(pos++);
|
|
this.ParamList = [];
|
|
for (let i = 0; i < count; i++)
|
|
{
|
|
const newObjParamList: {
|
|
Parameter: string
|
|
} = {
|
|
Parameter: ''
|
|
};
|
|
newObjParamList['Parameter'] = buf.toString('utf8', pos, length);
|
|
pos += length;
|
|
this.ParamList.push(newObjParamList);
|
|
}
|
|
return pos - startPos;
|
|
}
|
|
}
|
|
|