public void DeserializationFailsWithInsufficientData() { var value = new ProtocolHeader(Random.Chars(count: 4), Random.Byte(), new ProtocolVersion(Random.Byte(), Random.Byte(), Random.Byte())); var result = ProtocolHeader.Deserialize(new Byte[0], out var _, out var _); Assert.False(result); }
public void SerializedSizeIsEightBytes() { var value = new ProtocolHeader(Random.Chars(count: 4), Random.Byte(), new ProtocolVersion(Random.Byte(), Random.Byte(), Random.Byte())); var buffer = new ArrayBufferWriter <Byte>(8); value.Serialize(buffer); Assert.Equal(expected: 8, actual: buffer.WrittenCount); }
public void SerializationIsSymmetric() { var buffer = new ArrayBufferWriter <Byte>(8); var value = new ProtocolHeader(Random.Chars(count: 4), Random.Byte(), new ProtocolVersion(Random.Byte(), Random.Byte(), Random.Byte())); value.Serialize(buffer); ProtocolHeader.Deserialize(buffer.WrittenMemory.Span, out var deserialized, out var _); Assert.Equal(expected: value, actual: deserialized); }
public void DeserializationReturnsSurplusData() { var value = new ProtocolHeader(Random.Chars(count: 4), Random.Byte(), new ProtocolVersion(Random.Byte(), Random.Byte(), Random.Byte())); var extra = Random.UInt(); var buffer = new ArrayBufferWriter <Byte>(12); buffer.WriteSerializable(value) .WriteUInt32LE(extra); ProtocolHeader.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)); }