/// <inheritdoc /> public override int Deserialize(Core.Utility.BinaryReader reader) { var responseBuffer = new byte[UniqueIdSize]; var numRead = reader.Read(responseBuffer, 0, UniqueIdSize); var lowPart = System.BitConverter.ToUInt64(responseBuffer, 0); var highPart = System.BitConverter.ToUInt64(responseBuffer, 8); UniqueId = highPart.ToString("X16") + lowPart.ToString("X16"); var lowStatusBits = (DeviceStatusFlagsLo)reader.ReadUInt64(); var highStatusBits = (DeviceStatusFlagsHi)reader.ReadUInt64(); DeviceStatusFlags = new Model.DeviceStatusFlags(lowStatusBits, highStatusBits); numRead += StatusBytesSize; // TODO: throw here? System.Diagnostics.Debug.Assert(numRead == DeserializeByteCount, "Failed to deserialize correct number of bytes in DeviceStatusResponse."); return(numRead); }
/// <inheritdoc /> public override int Deserialize(Core.Utility.BinaryReader reader) { var header = reader.ReadBytes(MagicKey.Length); var bytesRead = header.Length; if (!header.SequenceEqual(MagicKey)) { throw new INTV.Core.UnexpectedFileTypeException("LUIGI"); } Version = reader.ReadByte(); bytesRead += sizeof(byte); if (Version > LuigiFileHeader.CurrentVersion) { // Perhaps throwing here is a bad idea... throw new System.InvalidOperationException(string.Format(System.Globalization.CultureInfo.CurrentCulture, Resources.Strings.UnsupportedLuigiVersion_Format, Version)); } Features = (LuigiFeatureFlags)reader.ReadUInt64(); bytesRead += sizeof(LuigiFeatureFlags); if (Version > 0) { Features2 = (LuigiFeatureFlags2)reader.ReadUInt64(); bytesRead += sizeof(LuigiFeatureFlags2); var uidBytes = reader.ReadBytes(VersionOneUidSize); if (uidBytes.Length < sizeof(ulong)) { throw new System.IO.EndOfStreamException(); } Uid = BitConverter.ToUInt64(uidBytes, 0); bytesRead += sizeof(ulong); var originalFormatKey = uidBytes.Skip(OriginalRomCrc32Size).Take(OriginalRomKeySize); var originalCrcData = uidBytes.Take(OriginalRomCrc32Size).ToArray(); if (originalFormatKey.SequenceEqual(RomKey)) { OriginalRomFormat = RomFormat.Rom; OriginalRomCrc32 = BitConverter.ToUInt32(originalCrcData, 0); } else { OriginalRomFormat = RomFormat.Bin; OriginalRomCrc32 = BitConverter.ToUInt32(originalCrcData, 0); if (!originalFormatKey.SequenceEqual(BinKey)) { OriginalCfgCrc32 = BitConverter.ToUInt32(originalFormatKey.ToArray(), 0); } } } Reserved = reader.ReadBytes(ReservedHeaderBytesSize); bytesRead += ReservedHeaderBytesSize; Crc = reader.ReadByte(); bytesRead += HeaderChecksumSize; ValidateHeaderBytesRead(bytesRead); ValidateHeaderCrc(reader, bytesRead); _deserializeByteCount = bytesRead; return(bytesRead); }