Files
node-metaverse/lib/classes/messages/TransferInventory.ts
2017-11-26 01:14:02 +00:00

107 lines
3.3 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 TransferInventoryMessage implements MessageBase
{
name = 'TransferInventory';
messageFlags = MessageFlags.Trusted | MessageFlags.Zerocoded | MessageFlags.FrequencyLow;
id = Message.TransferInventory;
InfoBlock: {
SourceID: UUID;
DestID: UUID;
TransactionID: UUID;
};
InventoryBlock: {
InventoryID: UUID;
Type: number;
}[];
ValidationBlock: {
NeedsValidation: boolean;
EstateID: number;
};
getSize(): number
{
return ((17) * this.InventoryBlock.length) + 54;
}
writeToBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
this.InfoBlock['SourceID'].writeToBuffer(buf, pos);
pos += 16;
this.InfoBlock['DestID'].writeToBuffer(buf, pos);
pos += 16;
this.InfoBlock['TransactionID'].writeToBuffer(buf, pos);
pos += 16;
const count = this.InventoryBlock.length;
buf.writeUInt8(this.InventoryBlock.length, pos++);
for (let i = 0; i < count; i++)
{
this.InventoryBlock[i]['InventoryID'].writeToBuffer(buf, pos);
pos += 16;
buf.writeInt8(this.InventoryBlock[i]['Type'], pos++);
}
buf.writeUInt8((this.ValidationBlock['NeedsValidation']) ? 1 : 0, pos++);
buf.writeUInt32LE(this.ValidationBlock['EstateID'], pos);
pos += 4;
return pos - startPos;
}
readFromBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
let varLength = 0;
const newObjInfoBlock: {
SourceID: UUID,
DestID: UUID,
TransactionID: UUID
} = {
SourceID: UUID.zero(),
DestID: UUID.zero(),
TransactionID: UUID.zero()
};
newObjInfoBlock['SourceID'] = new UUID(buf, pos);
pos += 16;
newObjInfoBlock['DestID'] = new UUID(buf, pos);
pos += 16;
newObjInfoBlock['TransactionID'] = new UUID(buf, pos);
pos += 16;
this.InfoBlock = newObjInfoBlock;
const count = buf.readUInt8(pos++);
this.InventoryBlock = [];
for (let i = 0; i < count; i++)
{
const newObjInventoryBlock: {
InventoryID: UUID,
Type: number
} = {
InventoryID: UUID.zero(),
Type: 0
};
newObjInventoryBlock['InventoryID'] = new UUID(buf, pos);
pos += 16;
newObjInventoryBlock['Type'] = buf.readInt8(pos++);
this.InventoryBlock.push(newObjInventoryBlock);
}
const newObjValidationBlock: {
NeedsValidation: boolean,
EstateID: number
} = {
NeedsValidation: false,
EstateID: 0
};
newObjValidationBlock['NeedsValidation'] = (buf.readUInt8(pos++) === 1);
newObjValidationBlock['EstateID'] = buf.readUInt32LE(pos);
pos += 4;
this.ValidationBlock = newObjValidationBlock;
return pos - startPos;
}
}