void DeserializeState(byte[] serializedState)
{
using (var ms = new MemoryStream(serializedState)) {
Serialization.Utils.DeserializeWithMd5CheckSum (ms, str => {
var version = Serialization.Utils.ReadInt (str);
if (version > Shovel.Api.Version) {
throw new Exceptions.VersionNotSupportedException ();
}
var stackIndex = Serialization.Utils.ReadInt (str);
var envIndex = Serialization.Utils.ReadInt (str);
this.programCounter = Serialization.Utils.ReadInt (str);
var bytes = new byte[32];
str.Read (bytes, 0, 32);
var actualBytecodeMd5 = Encoding.UTF8.GetString (bytes);
if (actualBytecodeMd5 != Utils.GetBytecodeMd5 (this.bytecode)) {
throw new Exceptions.BytecodeDoesntMatchState ();
}
// Read and ignore the source MD5.
str.Read (bytes, 0, 32);
// Read the number of ticks executed so far.
this.executedTicks = Serialization.Utils.ReadLong (ms);
// Read the number of used cells.
this.usedCells = Serialization.Utils.ReadInt (ms);
var ser = new Serialization.VmStateSerializer ();
ser.Deserialize (str, version, reader => {
this.stack = new Stack ((Value[])reader (stackIndex));
this.currentEnvironment = (VmEnvironment)reader (envIndex);
}
);
return null;
});
}
}