public void Deserialize(PacketChecksumType checksumType, byte[] data)
{
MemoryStream ms = new MemoryStream(data);
EndianBinaryReader reader = new EndianBinaryReader(EndianBitConverter.Little, ms);
if (reader.ReadByte() != 0x01)
{
throw new InvalidDataException("Message start byte must be 0x01");
}
StatusCode status = (StatusCode)reader.ReadByte();
if (status != StatusCode.CYRET_SUCCESS)
{
throw new BootloaderError(status);
}
ushort length = reader.ReadUInt16();
if (length > data.Length - 7)
{
throw new InvalidDataException("Invalid data length");
}
this.DeserializePayload(reader, length);
ushort checksum = reader.ReadUInt16();
if (checksum != PacketChecksum.ComputeChecksum(checksumType, data, length + 4))
{
throw new InvalidDataException("Invalid checksum");
}
if (reader.ReadByte() != 0x17)
{
throw new InvalidDataException("Message end byte must be 0x17");
}
}