コード例 #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);
        }