| | 1 | | namespace NLightning.Domain.ValueObjects; |
| | 2 | |
|
| | 3 | | using Interfaces; |
| | 4 | |
|
| | 5 | | public readonly struct Witness : IValueObject, IEquatable<Witness> |
| | 6 | | { |
| | 7 | | private readonly byte[] _value; |
| | 8 | |
|
| 16 | 9 | | public ushort Length => (ushort)_value.Length; |
| | 10 | |
|
| | 11 | | public Witness(byte[] value) |
| | 12 | | { |
| 40 | 13 | | _value = value; |
| 40 | 14 | | } |
| | 15 | |
|
| | 16 | | #region Equality |
| | 17 | | public bool Equals(Witness other) |
| | 18 | | { |
| 4 | 19 | | return _value.SequenceEqual(other._value); |
| | 20 | | } |
| | 21 | |
|
| | 22 | | public override bool Equals(object? obj) |
| | 23 | | { |
| 0 | 24 | | return obj is Witness other && Equals(other); |
| | 25 | | } |
| | 26 | |
|
| | 27 | | public override int GetHashCode() |
| | 28 | | { |
| 0 | 29 | | return _value.GetHashCode(); |
| | 30 | | } |
| | 31 | | #endregion |
| | 32 | |
|
| | 33 | | #region Implicit Operators |
| 12 | 34 | | public static implicit operator byte[](Witness s) => s._value; |
| 0 | 35 | | public static implicit operator Witness(byte[] value) => new(value); |
| 16 | 36 | | public static implicit operator ReadOnlyMemory<byte>(Witness s) => s._value; |
| | 37 | |
|
| | 38 | | public static bool operator ==(Witness left, Witness right) |
| | 39 | | { |
| 0 | 40 | | return left.Equals(right); |
| | 41 | | } |
| | 42 | |
|
| | 43 | | public static bool operator !=(Witness left, Witness right) |
| | 44 | | { |
| 0 | 45 | | return !(left == right); |
| | 46 | | } |
| | 47 | | #endregion |
| | 48 | | } |