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

86 lines
2.5 KiB
TypeScript
Raw Normal View History

2017-11-26 01:14:02 +00:00
// This file has been automatically generated by writeMessageClasses.js
import * as Long from 'long';
import { MessageFlags } from '../../enums/MessageFlags';
import { MessageBase } from '../MessageBase';
import { Message } from '../../enums/Message';
2017-11-26 01:14:02 +00:00
export class ScriptDataReplyMessage implements MessageBase
{
name = 'ScriptDataReply';
messageFlags = MessageFlags.Trusted | MessageFlags.FrequencyLow;
id = Message.ScriptDataReply;
DataBlock: {
Hash: Long;
Reply: Buffer;
2017-11-26 01:14:02 +00:00
}[];
getSize(): number
{
return this.calculateVarVarSize(this.DataBlock, 'Reply', 2) + ((8) * this.DataBlock.length) + 1;
2017-11-26 01:14:02 +00:00
}
2020-11-19 16:27:29 +00: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;
const count = this.DataBlock.length;
buf.writeUInt8(this.DataBlock.length, pos++);
for (let i = 0; i < count; i++)
{
buf.writeInt32LE(this.DataBlock[i]['Hash'].low, pos);
pos += 4;
buf.writeInt32LE(this.DataBlock[i]['Hash'].high, pos);
pos += 4;
buf.writeUInt16LE(this.DataBlock[i]['Reply'].length, pos);
pos += 2;
this.DataBlock[i]['Reply'].copy(buf, pos);
2017-11-26 01:14:02 +00:00
pos += this.DataBlock[i]['Reply'].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;
if (pos >= buf.length)
{
return pos - startPos;
}
2017-11-26 01:14:02 +00:00
const count = buf.readUInt8(pos++);
this.DataBlock = [];
for (let i = 0; i < count; i++)
{
const newObjDataBlock: {
Hash: Long,
Reply: Buffer
2017-11-26 01:14:02 +00:00
} = {
Hash: Long.ZERO,
Reply: Buffer.allocUnsafe(0)
2017-11-26 01:14:02 +00:00
};
newObjDataBlock['Hash'] = new Long(buf.readInt32LE(pos), buf.readInt32LE(pos+4));
pos += 8;
varLength = buf.readUInt16LE(pos);
pos += 2;
newObjDataBlock['Reply'] = buf.slice(pos, pos + varLength);
2017-11-26 01:14:02 +00:00
pos += varLength;
this.DataBlock.push(newObjDataBlock);
}
return pos - startPos;
}
}