Пример #1
0
        public void DeserializationFailsWithInvalidFrameTerminator()
        {
            var buffer = new ArrayBufferWriter <Byte>(8);
            var value  = new RawFrame(Random.Enum <FrameType>(), Random.UShort(), Random.Bytes(Random.UShort()));

            value.Serialize(buffer);
            var modifiedBuffer = buffer.WrittenMemory.ToArray();

            modifiedBuffer[modifiedBuffer.Length - 1] = 0x00;

            Assert.Throws <FramingErrorException>(() => RawFrame.Deserialize(modifiedBuffer.AsSpan(), out var _, out var _));
        }
Пример #2
0
        public void SerializationIsSymmetric()
        {
            var buffer = new ArrayBufferWriter <Byte>();
            var value  = new RawFrame(Random.Enum <FrameType>(), Random.UShort(), Random.Bytes(Random.UShort()));

            value.Serialize(buffer);
            RawFrame.Deserialize(buffer.WrittenMemory.Span, out var deserialized, out var _);

            Assert.Equal(expected: value.Channel, actual: deserialized.Channel);
            Assert.Equal(expected: value.Payload.ToArray(), actual: deserialized.Payload.ToArray());
            Assert.Equal(expected: value.Size, actual: deserialized.Size);
            Assert.Equal(expected: value.Type, actual: deserialized.Type);
        }
Пример #3
0
        public void DeserializationReturnsSurplusData()
        {
            var value  = new RawFrame(Random.Enum <FrameType>(), Random.UShort(), Random.Bytes(Random.UShort()));
            var extra  = Random.UInt();
            var buffer = new ArrayBufferWriter <Byte>(12);

            buffer.WriteSerializable(value)
            .WriteUInt32LE(extra);

            RawFrame.Deserialize(buffer.WrittenMemory.Span, out var _, out var surplus);

            Assert.Equal(expected: sizeof(UInt32), actual: surplus.Length);
            Assert.Equal(expected: extra, actual: BitConverter.ToUInt32(surplus));
        }
Пример #4
0
        public void DeserializationFailsWithInsufficientData()
        {
            var result = RawFrame.Deserialize(new Byte[0], out var _, out var _);

            Assert.False(result);
        }