25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.6 KiB

  1. using JT808.Protocol.Attributes;
  2. using JT808.Protocol.Formatters;
  3. using JT808.Protocol.MessagePack;
  4. namespace JT808.Protocol.MessageBody
  5. {
  6. /// <summary>
  7. /// 数据压缩上报
  8. /// 0x0901
  9. /// </summary>
  10. public class JT808_0x0901 : JT808Bodies, IJT808MessagePackFormatter<JT808_0x0901>
  11. {
  12. public override ushort MsgId { get; } = 0x0901;
  13. /// <summary>
  14. /// 未压缩消息长度
  15. /// </summary>
  16. public uint UnCompressMessageLength { get; set; }
  17. /// <summary>
  18. /// 未压缩消息体
  19. /// 压缩消息体为需要压缩的消息经过 GZIP 压缩算法后的消息
  20. /// 可实现 <see cref="JT808.Protocol.IJT808ICompress"/>自定义压缩算法
  21. /// </summary>
  22. public byte[] UnCompressMessage { get; set; }
  23. public JT808_0x0901 Deserialize(ref JT808MessagePackReader reader, IJT808Config config)
  24. {
  25. JT808_0x0901 jT808_0X0901 = new JT808_0x0901();
  26. var compressMessageLength = reader.ReadUInt32();
  27. var data = reader.ReadArray((int)compressMessageLength);
  28. jT808_0X0901.UnCompressMessage = config.Compress.Decompress(data.ToArray());
  29. jT808_0X0901.UnCompressMessageLength = (uint)jT808_0X0901.UnCompressMessage.Length;
  30. return jT808_0X0901;
  31. }
  32. public void Serialize(ref JT808MessagePackWriter writer, JT808_0x0901 value, IJT808Config config)
  33. {
  34. var data = config.Compress.Compress(value.UnCompressMessage);
  35. writer.WriteUInt32((uint)data.Length);
  36. writer.WriteArray(data);
  37. }
  38. }
  39. }