Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

49 linhas
1.7 KiB

  1. using JT808.Protocol.Attributes;
  2. using JT808.Protocol.Formatters;
  3. using JT808.Protocol.Formatters.MessageBodyFormatters;
  4. using JT808.Protocol.MessagePack;
  5. namespace JT808.Protocol.MessageBody
  6. {
  7. /// <summary>
  8. /// 信息服务
  9. /// 0x8304
  10. /// </summary>
  11. [JT808Formatter(typeof(JT808_0x8304_Formatter))]
  12. public class JT808_0x8304 : JT808Bodies, IJT808MessagePackFormatter<JT808_0x8304>
  13. {
  14. /// <summary>
  15. /// 信息类型
  16. /// </summary>
  17. public byte InformationType { get; set; }
  18. /// <summary>
  19. /// 信息长度
  20. /// </summary>
  21. public ushort InformationLength { get; set; }
  22. /// <summary>
  23. /// 信息内容
  24. /// 经 GBK 编码
  25. /// </summary>
  26. public string InformationContent { get; set; }
  27. public JT808_0x8304 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
  28. {
  29. JT808_0x8304 jT808_0X8304 = new JT808_0x8304();
  30. jT808_0X8304.InformationType = reader.ReadByte();
  31. jT808_0X8304.InformationLength = reader.ReadUInt16();
  32. jT808_0X8304.InformationContent = reader.ReadString(jT808_0X8304.InformationLength);
  33. return jT808_0X8304;
  34. }
  35. public void Serialize(ref JT808MessagePackWriter writer, JT808_0x8304 value, IJT808Config config)
  36. {
  37. writer.WriteByte(value.InformationType);
  38. // 先计算内容长度(汉字为两个字节)
  39. writer.Skip(2, out int position);
  40. writer.WriteString(value.InformationContent);
  41. ushort length = (ushort)(writer.GetCurrentPosition() - position - 2);
  42. writer.WriteUInt16Return(length, position);
  43. }
  44. }
  45. }