Files
node-metaverse/lib/classes/messages/GroupVoteHistoryItemReply.ts
2020-11-19 17:10:19 +00:00

217 lines
8.0 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 GroupVoteHistoryItemReplyMessage implements MessageBase
{
name = 'GroupVoteHistoryItemReply';
messageFlags = MessageFlags.Trusted | MessageFlags.Zerocoded | MessageFlags.FrequencyLow;
id = Message.GroupVoteHistoryItemReply;
AgentData: {
AgentID: UUID;
GroupID: UUID;
};
TransactionData: {
TransactionID: UUID;
TotalNumItems: number;
};
HistoryItemData: {
VoteID: UUID;
TerseDateID: Buffer;
StartDateTime: Buffer;
EndDateTime: Buffer;
VoteInitiator: UUID;
VoteType: Buffer;
VoteResult: Buffer;
Majority: number;
Quorum: number;
ProposalText: Buffer;
};
VoteItem: {
CandidateID: UUID;
VoteCast: Buffer;
NumVotes: number;
}[];
getSize(): number
{
return (this.HistoryItemData['TerseDateID'].length + 1 + this.HistoryItemData['StartDateTime'].length + 1 + this.HistoryItemData['EndDateTime'].length + 1 + this.HistoryItemData['VoteType'].length + 1 + this.HistoryItemData['VoteResult'].length + 1 + this.HistoryItemData['ProposalText'].length + 2) + this.calculateVarVarSize(this.VoteItem, 'VoteCast', 1) + ((20) * this.VoteItem.length) + 93;
}
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;
}
writeToBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
this.AgentData['AgentID'].writeToBuffer(buf, pos);
pos += 16;
this.AgentData['GroupID'].writeToBuffer(buf, pos);
pos += 16;
this.TransactionData['TransactionID'].writeToBuffer(buf, pos);
pos += 16;
buf.writeUInt32LE(this.TransactionData['TotalNumItems'], pos);
pos += 4;
this.HistoryItemData['VoteID'].writeToBuffer(buf, pos);
pos += 16;
buf.writeUInt8(this.HistoryItemData['TerseDateID'].length, pos++);
this.HistoryItemData['TerseDateID'].copy(buf, pos);
pos += this.HistoryItemData['TerseDateID'].length;
buf.writeUInt8(this.HistoryItemData['StartDateTime'].length, pos++);
this.HistoryItemData['StartDateTime'].copy(buf, pos);
pos += this.HistoryItemData['StartDateTime'].length;
buf.writeUInt8(this.HistoryItemData['EndDateTime'].length, pos++);
this.HistoryItemData['EndDateTime'].copy(buf, pos);
pos += this.HistoryItemData['EndDateTime'].length;
this.HistoryItemData['VoteInitiator'].writeToBuffer(buf, pos);
pos += 16;
buf.writeUInt8(this.HistoryItemData['VoteType'].length, pos++);
this.HistoryItemData['VoteType'].copy(buf, pos);
pos += this.HistoryItemData['VoteType'].length;
buf.writeUInt8(this.HistoryItemData['VoteResult'].length, pos++);
this.HistoryItemData['VoteResult'].copy(buf, pos);
pos += this.HistoryItemData['VoteResult'].length;
buf.writeFloatLE(this.HistoryItemData['Majority'], pos);
pos += 4;
buf.writeInt32LE(this.HistoryItemData['Quorum'], pos);
pos += 4;
buf.writeUInt16LE(this.HistoryItemData['ProposalText'].length, pos);
pos += 2;
this.HistoryItemData['ProposalText'].copy(buf, pos);
pos += this.HistoryItemData['ProposalText'].length;
const count = this.VoteItem.length;
buf.writeUInt8(this.VoteItem.length, pos++);
for (let i = 0; i < count; i++)
{
this.VoteItem[i]['CandidateID'].writeToBuffer(buf, pos);
pos += 16;
buf.writeUInt8(this.VoteItem[i]['VoteCast'].length, pos++);
this.VoteItem[i]['VoteCast'].copy(buf, pos);
pos += this.VoteItem[i]['VoteCast'].length;
buf.writeInt32LE(this.VoteItem[i]['NumVotes'], pos);
pos += 4;
}
return pos - startPos;
}
readFromBuffer(buf: Buffer, pos: number): number
{
const startPos = pos;
let varLength = 0;
const newObjAgentData: {
AgentID: UUID,
GroupID: UUID
} = {
AgentID: UUID.zero(),
GroupID: UUID.zero()
};
newObjAgentData['AgentID'] = new UUID(buf, pos);
pos += 16;
newObjAgentData['GroupID'] = new UUID(buf, pos);
pos += 16;
this.AgentData = newObjAgentData;
const newObjTransactionData: {
TransactionID: UUID,
TotalNumItems: number
} = {
TransactionID: UUID.zero(),
TotalNumItems: 0
};
newObjTransactionData['TransactionID'] = new UUID(buf, pos);
pos += 16;
newObjTransactionData['TotalNumItems'] = buf.readUInt32LE(pos);
pos += 4;
this.TransactionData = newObjTransactionData;
const newObjHistoryItemData: {
VoteID: UUID,
TerseDateID: Buffer,
StartDateTime: Buffer,
EndDateTime: Buffer,
VoteInitiator: UUID,
VoteType: Buffer,
VoteResult: Buffer,
Majority: number,
Quorum: number,
ProposalText: Buffer
} = {
VoteID: UUID.zero(),
TerseDateID: Buffer.allocUnsafe(0),
StartDateTime: Buffer.allocUnsafe(0),
EndDateTime: Buffer.allocUnsafe(0),
VoteInitiator: UUID.zero(),
VoteType: Buffer.allocUnsafe(0),
VoteResult: Buffer.allocUnsafe(0),
Majority: 0,
Quorum: 0,
ProposalText: Buffer.allocUnsafe(0)
};
newObjHistoryItemData['VoteID'] = new UUID(buf, pos);
pos += 16;
varLength = buf.readUInt8(pos++);
newObjHistoryItemData['TerseDateID'] = buf.slice(pos, pos + varLength);
pos += varLength;
varLength = buf.readUInt8(pos++);
newObjHistoryItemData['StartDateTime'] = buf.slice(pos, pos + varLength);
pos += varLength;
varLength = buf.readUInt8(pos++);
newObjHistoryItemData['EndDateTime'] = buf.slice(pos, pos + varLength);
pos += varLength;
newObjHistoryItemData['VoteInitiator'] = new UUID(buf, pos);
pos += 16;
varLength = buf.readUInt8(pos++);
newObjHistoryItemData['VoteType'] = buf.slice(pos, pos + varLength);
pos += varLength;
varLength = buf.readUInt8(pos++);
newObjHistoryItemData['VoteResult'] = buf.slice(pos, pos + varLength);
pos += varLength;
newObjHistoryItemData['Majority'] = buf.readFloatLE(pos);
pos += 4;
newObjHistoryItemData['Quorum'] = buf.readInt32LE(pos);
pos += 4;
varLength = buf.readUInt16LE(pos);
pos += 2;
newObjHistoryItemData['ProposalText'] = buf.slice(pos, pos + varLength);
pos += varLength;
this.HistoryItemData = newObjHistoryItemData;
if (pos >= buf.length)
{
return pos - startPos;
}
const count = buf.readUInt8(pos++);
this.VoteItem = [];
for (let i = 0; i < count; i++)
{
const newObjVoteItem: {
CandidateID: UUID,
VoteCast: Buffer,
NumVotes: number
} = {
CandidateID: UUID.zero(),
VoteCast: Buffer.allocUnsafe(0),
NumVotes: 0
};
newObjVoteItem['CandidateID'] = new UUID(buf, pos);
pos += 16;
varLength = buf.readUInt8(pos++);
newObjVoteItem['VoteCast'] = buf.slice(pos, pos + varLength);
pos += varLength;
newObjVoteItem['NumVotes'] = buf.readInt32LE(pos);
pos += 4;
this.VoteItem.push(newObjVoteItem);
}
return pos - startPos;
}
}