kunlang_tbox/include/protocol/protocol_codec.h

25 lines
768 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include "protocol_struct.h"
#include <vector>
#include <string>
#include <cstdint>
namespace ProtocolCodec
{
// 获取当前北京时间,返回 6 字节 vector {year, month, day, hour, minute, second}
std::vector<uint8_t> get_current_time_bytes();
// 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);
std::vector<uint8_t> make_ack_response(const FullPacket &request, bool result);
} // namespace ProtocolCodec