kunlang_mqtt_client/include/protocol_codec.hpp

28 lines
832 B
C++
Raw Normal View History

2025-07-10 17:36:16 +08:00
#pragma once
#include <vector>
#include <string>
#include <cstdint>
#include "protocol_struct.hpp"
#include "mqtt_config.hpp"
namespace ProtocolCodec
{
// BCC 校验
uint8_t calculate_bcc(const std::vector<uint8_t> &data);
// 编码 FullPacket 为字节流(使用大端)
std::vector<uint8_t> encode_full_packet(const FullPacket &packet);
// 解码字节流为 FullPacket成功返回 packet否则 std::nullopt
std::optional<FullPacket> decode_full_packet(const std::vector<uint8_t> &buffer);
// 构造心跳包
FullPacket create_heartbeat_packet(const std::string &vin);
std::optional<MqttParamSetting> parse_mqtt_param_setting(const std::vector<uint8_t> &data);
std::vector<uint8_t> make_ack_response(const FullPacket &request, bool result);
} // namespace ProtocolCodec