diff --git a/DcsBiosCommunicator/DataParsers/DataParser.cs b/DcsBiosCommunicator/DataParsers/DataParser.cs index 9680939..af51e84 100644 --- a/DcsBiosCommunicator/DataParsers/DataParser.cs +++ b/DcsBiosCommunicator/DataParsers/DataParser.cs @@ -1,18 +1,12 @@ namespace DcsBios.Communicator.DataParsers; -public abstract class DataParser +public abstract class DataParser(in ushort address, in string biosCode) { - public ushort Address { get; } + public ushort Address { get; } = address; - public string BiosCode { get; } + public string BiosCode { get; } = biosCode; public T CurrentValue { get; protected set; } = default!; - protected DataParser(in ushort address, in string biosCode) - { - Address = address; - BiosCode = biosCode; - } - public abstract void AddData(in ushort address, in ushort data); } diff --git a/DcsBiosCommunicator/DataParsers/IntegerParser.cs b/DcsBiosCommunicator/DataParsers/IntegerParser.cs index ddb5450..7322971 100644 --- a/DcsBiosCommunicator/DataParsers/IntegerParser.cs +++ b/DcsBiosCommunicator/DataParsers/IntegerParser.cs @@ -3,16 +3,11 @@ namespace DcsBios.Communicator.DataParsers; -public class IntegerParser : DataParser +public class IntegerParser(in ushort mask, [Range(0, 15)] in byte shift, in string biosCode) + : DataParser(default, biosCode) { - private readonly ushort _mask; - private readonly byte _shift; - - public IntegerParser(in ushort mask, [Range(0, 15)] in byte shift, in string biosCode) : base(default, biosCode) - { - _mask = mask; - _shift = shift; - } + private readonly ushort _mask = mask; + private readonly byte _shift = shift; public override void AddData(in ushort address, in ushort data) { diff --git a/DcsBiosCommunicator/DataParsers/StringParser.cs b/DcsBiosCommunicator/DataParsers/StringParser.cs index b5e4340..7a76189 100644 --- a/DcsBiosCommunicator/DataParsers/StringParser.cs +++ b/DcsBiosCommunicator/DataParsers/StringParser.cs @@ -1,29 +1,19 @@ using System; +using System.ComponentModel.DataAnnotations; namespace DcsBios.Communicator.DataParsers; -public sealed class StringParser : DataParser +public sealed class StringParser(in ushort address, [Range(1, 64)] in byte length, in string biosCode) + : DataParser(address, biosCode) { public bool DataReady => _bufferFilledBits == _bufferSizeBits; - public byte Length { get; } - private readonly byte[] _buffer; - private readonly long _bufferSizeBits; + public byte Length { get; } = length; + private readonly byte[] _buffer = new byte[length]; + private readonly long _bufferSizeBits = (2L << (length - 1)) - 1; private long _bufferFilledBits; - private readonly ushort _baseAddress; - - public StringParser(in ushort address, in byte length, in string biosCode) : base(address, biosCode) - { - if (length is < 1 or > 64) - throw new ArgumentOutOfRangeException(nameof(length), length, - $"Length of {biosCode} should be between 1 and 64, inclusive."); - - Length = length; - _buffer = new byte[length]; - _bufferSizeBits = (2L << (length - 1)) - 1; - _baseAddress = address; - } + private readonly ushort _baseAddress = address; private bool SetCharacter(int index, byte b) { diff --git a/DcsBiosCommunicator/IntegerHandler.cs b/DcsBiosCommunicator/IntegerHandler.cs index ce72106..4f74de4 100644 --- a/DcsBiosCommunicator/IntegerHandler.cs +++ b/DcsBiosCommunicator/IntegerHandler.cs @@ -4,15 +4,9 @@ namespace DcsBios.Communicator; -internal class IntegerHandler +internal class IntegerHandler(in ushort address, IEnumerable maskShifts) { - public int Address { get; } + public ushort Address { get; } = address; - public IList MaskShifts { get; } - - public IntegerHandler(in int address, IEnumerable maskShifts) - { - Address = address; - MaskShifts = maskShifts.ToList(); - } + public IList MaskShifts { get; } = maskShifts.ToList(); }