public void PayloadTest(IMessagePayload payload, PayloadType expPlType) { var stream = new FastStream(); payload.Serialize(stream); Assert.Empty(stream.ToByteArray()); Assert.Equal(expPlType, payload.PayloadType); Assert.Equal(new byte[] { 0x5d, 0xf6, 0xe0, 0xe2 }, payload.GetChecksum()); }
/// <summary> /// Initializes a new instance of <see cref="Message"/> with the given <see cref="IMessagePayload"/> /// and sets network magic based on the given <see cref="NetworkType"/>. /// </summary> /// <exception cref="ArgumentException"/> /// <exception cref="ArgumentNullException"/> /// <exception cref="ArgumentOutOfRangeException"/> /// <param name="payload">Message payload</param> /// <param name="netType">Network type</param> public Message(IMessagePayload payload, NetworkType netType) : this(netType) { if (payload is null) { throw new ArgumentNullException(nameof(payload), "Payload can not be null."); } byte[] temp = Encoding.ASCII.GetBytes(payload.PayloadType.ToString().ToLower()); if (temp.Length > CommandNameSize) { throw new ArgumentOutOfRangeException(nameof(payload.PayloadType), $"Payload name can not be longer than {CommandNameSize}."); } PayloadName = new byte[CommandNameSize]; Buffer.BlockCopy(temp, 0, PayloadName, 0, temp.Length); var stream = new FastStream(); payload.Serialize(stream); PayloadData = stream.ToByteArray(); }