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

104 lines
3.1 KiB
TypeScript
Raw Normal View History

2017-11-26 01:14:02 +00:00
// 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';
2017-11-26 01:14:02 +00:00
export class SystemMessageMessage implements MessageBase
{
name = 'SystemMessage';
messageFlags = MessageFlags.Trusted | MessageFlags.Zerocoded | MessageFlags.FrequencyLow;
id = Message.SystemMessage;
MethodData: {
Method: Buffer;
2017-11-26 01:14:02 +00:00
Invoice: UUID;
Digest: Buffer;
};
ParamList: {
Parameter: Buffer;
2017-11-26 01:14:02 +00:00
}[];
getSize(): number
{
return (this.MethodData['Method'].length + 1) + this.calculateVarVarSize(this.ParamList, 'Parameter', 1) + 49;
2017-11-26 01:14:02 +00:00
}
2021-09-23 17:21:36 +01:00
calculateVarVarSize(block: { [key: string]: any }[], paramName: string, extraPerVar: number): number
2017-11-26 01:14:02 +00:00
{
let size = 0;
2020-11-19 16:27:29 +00:00
for (const bl of block)
2017-11-26 01:14:02 +00:00
{
size += bl[paramName].length + extraPerVar;
2020-11-19 16:27:29 +00:00
}
2017-11-26 01:14:02 +00:00
return size;
}
// @ts-ignore
2017-11-26 01:14:02 +00:00
writeToBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
buf.writeUInt8(this.MethodData['Method'].length, pos++);
this.MethodData['Method'].copy(buf, pos);
2017-11-26 01:14:02 +00:00
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.writeUInt8(this.ParamList[i]['Parameter'].length, pos++);
this.ParamList[i]['Parameter'].copy(buf, pos);
2017-11-26 01:14:02 +00:00
pos += this.ParamList[i]['Parameter'].length;
}
return pos - startPos;
}
// @ts-ignore
2017-11-26 01:14:02 +00:00
readFromBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
let varLength = 0;
const newObjMethodData: {
Method: Buffer,
2017-11-26 01:14:02 +00:00
Invoice: UUID,
Digest: Buffer
} = {
Method: Buffer.allocUnsafe(0),
2017-11-26 01:14:02 +00:00
Invoice: UUID.zero(),
Digest: Buffer.allocUnsafe(0)
};
varLength = buf.readUInt8(pos++);
newObjMethodData['Method'] = buf.slice(pos, pos + varLength);
2017-11-26 01:14:02 +00:00
pos += varLength;
newObjMethodData['Invoice'] = new UUID(buf, pos);
pos += 16;
newObjMethodData['Digest'] = buf.slice(pos, pos + 32);
pos += 32;
this.MethodData = newObjMethodData;
if (pos >= buf.length)
{
return pos - startPos;
}
2017-11-26 01:14:02 +00:00
const count = buf.readUInt8(pos++);
this.ParamList = [];
for (let i = 0; i < count; i++)
{
const newObjParamList: {
Parameter: Buffer
2017-11-26 01:14:02 +00:00
} = {
Parameter: Buffer.allocUnsafe(0)
2017-11-26 01:14:02 +00:00
};
varLength = buf.readUInt8(pos++);
newObjParamList['Parameter'] = buf.slice(pos, pos + varLength);
2017-11-26 01:14:02 +00:00
pos += varLength;
this.ParamList.push(newObjParamList);
}
return pos - startPos;
}
}