public void Read(Reader reader) { this.DataType = (DataType)reader.ReadByte(); switch (this.DataType) { case DataType.Int: Value = reader.ReadInt(); break; case DataType.UShort: Value = reader.ReadUShort(); break; case DataType.Long: Value = reader.ReadLong(); break; case DataType.Byte: Value = reader.ReadByte(); break; case DataType.Bool: Value = reader.ReadBool(); break; case DataType.String: Value = reader.ReadString(); break; case DataType.ByteArray: Value = reader.ReadByteArray(); break; } }
/// <summary> /// Reconstructs this command from a serialized command and returns the size of the command. /// </summary> public int Reconstruct(byte[] Source, int StartIndex) { reader.Initialize(Source, StartIndex); ControllerID = reader.ReadByte(); LeInput = (InputCode)reader.ReadByte(); ValuesMask = reader.ReadUInt(); HasPosition = GetMaskBool(ValuesMask, DataType.Position); HasTarget = GetMaskBool(ValuesMask, DataType.Target); HasFlag = GetMaskBool(ValuesMask, DataType.Flag); HasCoord = GetMaskBool(ValuesMask, DataType.Coord); HasCount = GetMaskBool(ValuesMask, DataType.Count); HasSelect = GetMaskBool(ValuesMask, DataType.Select); if (HasPosition) { _position.x = reader.ReadInt(); _position.y = reader.ReadInt(); } if (HasTarget) { _target = reader.ReadUShort(); } if (HasFlag) { _flag = reader.ReadBool(); } if (HasCoord) { _coord.x = reader.ReadInt(); _coord.y = reader.ReadInt(); } if (HasCount) { _count = reader.ReadInt(); } if (HasSelect) { Select = new Selection(); reader.count += Select.Reconstruct( AgentController.InstanceManagers[ControllerID], reader.source, reader.count); } return(reader.count - StartIndex); }