public void Read(Reader reader) { ushort size = reader.ReadUShort(); using (MemoryStream stream = new MemoryStream(reader.Source, reader.Position, (int)size)) { object o = binaryFormatter.Deserialize(stream); this.ObjectValue = (object[])o; } }
/// <summary> /// Reconstructs this command from a serialized command and returns the size of the command. /// </summary> public int Reconstruct(byte[] Source, int StartIndex = 0) { reader.Initialize(Source, StartIndex); ControllerID = reader.ReadByte(); LeInput = reader.ReadUShort(); this.ContainedTypesCount = reader.ReadUShort(); for (int i = 0; i < this.ContainedTypesCount; i++) { ushort dataID = reader.ReadUShort(); ushort dataCount = reader.ReadUShort(); FastList <ICommandData> items = GetItemsList(dataID); Type dataType = RegisteredData.GetReversed(dataID); for (int j = 0; j < dataCount; j++) { ICommandData item = Activator.CreateInstance(dataType) as ICommandData; item.Read(reader); items.Add(item); } } return(reader.Position - StartIndex); }
/// <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); }
public void Read(Reader reader) { this.DataType = (DataType)reader.ReadByte(); switch (this.DataType) { case DataType.Int: Value = reader.ReadInt(); break; case DataType.UInt: Value = reader.ReadUInt(); 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; } }