--- /dev/null
+using System;
+using System.Runtime.Serialization;
+
+namespace Impostor.Api
+{
+ public class ImpostorProtocolException : ImpostorException
+ {
+ public ImpostorProtocolException()
+ {
+ }
+
+ protected ImpostorProtocolException(SerializationInfo info, StreamingContext context) : base(info, context)
+ {
+ }
+
+ public ImpostorProtocolException(string? message) : base(message)
+ {
+ }
+
+ public ImpostorProtocolException(string? message, Exception? innerException) : base(message, innerException)
+ {
+ }
+ }
+}
using System.Buffers.Binary;
using System.Runtime.CompilerServices;
using System.Text;
+using Impostor.Api;
using Impostor.Api.Net.Messages;
using Microsoft.Extensions.ObjectPool;
public void RemoveMessage(IMessageReader message)
{
+ if (message.Buffer != Buffer)
+ {
+ throw new ImpostorProtocolException("Tried to remove message from a message that does not have the same buffer.");
+ }
+
// Offset of where to start removing.
var offsetStart = message.Offset - 3;
using System;
using System.Linq;
+using Impostor.Api;
using Impostor.Hazel;
using Impostor.Hazel.Extensions;
using Microsoft.Extensions.DependencyInjection;
var bufferCopy = new byte[messageWriter.Length];
Buffer.BlockCopy(messageWriter.Buffer, 0, bufferCopy, 0, bufferCopy.Length);
+ var bufferCopyTwo = new byte[messageWriter.Length];
+ Buffer.BlockCopy(messageWriter.Buffer, 0, bufferCopyTwo, 0, bufferCopyTwo.Length);
+
// Do the magic.
var readerPool = CreateReaderPool();
var reader = readerPool.Get();
// Check if the magic was successful.
Assert.Equal(messageExpected.Length, reader.Length);
Assert.Equal(messageExpected.ToByteArray(true), reader.Buffer.Take(reader.Length).ToArray());
+
+ // Test ownership.
+ var readerTwo = readerPool.Get();
+
+ readerTwo.Update(bufferCopyTwo);
+
+ Assert.Throws<ImpostorProtocolException>(() => reader.RemoveMessage(readerTwo.ReadMessage()));
}
[Fact]