You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 line
889B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace NearCardAttendance.Service.TcpServer.Protocol
  7. {
  8. public class ProtocolWrapper
  9. {
  10. private string Length { get; }
  11. private string FuncNo { get; }
  12. private string SeqNo { get; }
  13. private string Data { get; }
  14. public ProtocolWrapper(string funcNo,string seqNo,string data)
  15. {
  16. FuncNo =funcNo;
  17. SeqNo=seqNo;
  18. Data=data;
  19. Length = CalculateMessageLength();
  20. }
  21. private string CalculateMessageLength()
  22. {
  23. return string.Format("{0:D4}", GenerateProtocolString().Length + 4);
  24. }
  25. public string GenerateProtocolString()
  26. {
  27. return $"{Length}{FuncNo}{SeqNo}{Data}";
  28. }
  29. }
  30. }