| | | 1 | | using System.Text; |
| | | 2 | | |
| | | 3 | | namespace NLightning.Domain.Protocol.Payloads; |
| | | 4 | | |
| | | 5 | | using Channels.ValueObjects; |
| | | 6 | | using Interfaces; |
| | | 7 | | using Messages; |
| | | 8 | | |
| | | 9 | | /// <summary> |
| | | 10 | | /// Represents an error payload. |
| | | 11 | | /// </summary> |
| | | 12 | | /// <remarks> |
| | | 13 | | /// An error payload is used to communicate an error to the other party. |
| | | 14 | | /// </remarks> |
| | | 15 | | /// <seealso cref="ErrorMessage"/> |
| | | 16 | | public class ErrorPayload : IMessagePayload |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// The channel id. |
| | | 20 | | /// </summary> |
| | | 21 | | /// <remarks> |
| | | 22 | | /// The channel id is used to identify the channel the error is related to. |
| | | 23 | | /// </remarks> |
| | 56 | 24 | | public ChannelId ChannelId { get; } = ChannelId.Zero; |
| | | 25 | | |
| | | 26 | | /// <summary> |
| | | 27 | | /// The error data. |
| | | 28 | | /// </summary> |
| | | 29 | | /// <remarks> |
| | | 30 | | /// The error data is used to communicate the error. |
| | | 31 | | /// </remarks> |
| | 52 | 32 | | public byte[]? Data { get; } |
| | | 33 | | |
| | 28 | 34 | | public ErrorPayload(byte[] data) |
| | | 35 | | { |
| | 28 | 36 | | Data = data; |
| | 28 | 37 | | } |
| | | 38 | | |
| | 12 | 39 | | public ErrorPayload(ChannelId? channelId, byte[] data) : this(data) |
| | | 40 | | { |
| | 12 | 41 | | if (channelId.HasValue) |
| | 12 | 42 | | ChannelId = channelId.Value; |
| | 12 | 43 | | } |
| | | 44 | | |
| | 0 | 45 | | public ErrorPayload(ChannelId? channelId, string message) : this(channelId, Encoding.UTF8.GetBytes(message)) |
| | | 46 | | { |
| | 0 | 47 | | } |
| | | 48 | | |
| | 12 | 49 | | public ErrorPayload(string message) : this(Encoding.UTF8.GetBytes(message)) |
| | | 50 | | { |
| | 12 | 51 | | } |
| | | 52 | | } |