/// <summary> /// Asserts that the specified number of bytes can be read from <c>data</c> starting at <c>index</c> /// <para></para> /// The number of bytes must be pushed onto the evaluation stack /// </summary> public void AssertLength() { LoadIndex(); // stack: [length, index] Il.Add(); // stack: [length + index] LoadDataLength(); // stack: [length + index, dataLength] var bigEnoughLabel = Il.DefineLabel("bigEnough"); Il.Ble(bigEnoughLabel, true); Il.Ldstr("Unexpected end of data"); var constructor = typeof(DataCorruptedException).GetConstructor(new[] { typeof(string) }); if (constructor == null) { throw new MissingConstructorException(typeof(DataCorruptedException), typeof(string)); } Il.Newobj(constructor); Il.Throw(); Il.MarkLabel(bigEnoughLabel); }
/// <summary> /// Asserts that the specified number of bytes can be written to <c>result</c> starting at <c>index</c> /// <para></para> /// The number of bytes must be pushed onto the evaluation stack /// </summary> public void AssertLength() { LoadIndex(); // stack: [length, index] Il.Add(); // stack: [length + index] LoadResultLength(); // stack: [length + index, resultLength] var bigEnoughLabel = Il.DefineLabel("bigEnough"); Il.Ble(bigEnoughLabel, true); Il.Ldstr("Seems like the object being serialized has been changed during serialization"); var constructor = typeof(InvalidOperationException).GetConstructor(new[] { typeof(string) }); if (constructor == null) { throw new MissingConstructorException(typeof(InvalidOperationException), typeof(string)); } Il.Newobj(constructor); Il.Throw(); Il.MarkLabel(bigEnoughLabel); }