|
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
-
- namespace NearCardAttendance.Service.TcpServer.Protocol
- {
-
- public class ProtocolParser
- {
- public int MessageLength { get; private set; } = default!;
-
- public string FuncNo { get; private set; } = default!;
-
- public string SeqNo { get; private set; } = default!;
-
- public string Data { get; private set; } = default!;
- //private string _protocolString { get; set; } = default!;
- public ProtocolParser(string protocolString)
- {
- ParseProtocolString(protocolString);
- //_protocolString = protocolString;
- }
-
- private void ParseProtocolString(string protocolString)
- {
- try
- {
- _ = int.TryParse(protocolString.AsSpan(0, 4), out int messageLength);
- MessageLength = messageLength;
- FuncNo = protocolString.Substring(4,2);
- SeqNo = protocolString.Substring(6,4);
- Data = protocolString.Substring(10).TrimEnd();
- }
- catch (Exception e)
- {
-
- Console.WriteLine($"Error: {e.Message}");
- // throw new ArgumentException("Invalid protocol string format.");
- }
- }
- }
-
-
-
- }
|