tweak bbnow types

This commit is contained in:
2026-08-13 14:23:05 -05:00
parent de3572385b
commit 885a133080
3 changed files with 9 additions and 7 deletions
+3 -3
View File
@@ -4,7 +4,7 @@
const static char TAG[] = "bbnow_pub"; const static char TAG[] = "bbnow_pub";
size_t BBNowPubPacket::serialize_size() { size_t BBNowPubPacket::serialize_size() const {
switch (this->packet_type) { switch (this->packet_type) {
case BBNowPubPacketType::NONE: case BBNowPubPacketType::NONE:
return -1; return -1;
@@ -14,7 +14,7 @@ size_t BBNowPubPacket::serialize_size() {
return -1; return -1;
} }
std::vector<uint8_t> BBNowPubPacket::serialize() { std::vector<uint8_t> BBNowPubPacket::serialize() const {
auto buf = std::vector<uint8_t>(); auto buf = std::vector<uint8_t>();
if (this->serialize_size() == -1) { if (this->serialize_size() == -1) {
@@ -25,7 +25,7 @@ std::vector<uint8_t> BBNowPubPacket::serialize() {
return buf; return buf;
} }
size_t BBNowPubPacket::serialize_into(std::vector<uint8_t>& buf) { size_t BBNowPubPacket::serialize_into(std::vector<uint8_t>& buf) const {
size_t initial_size = buf.size(); size_t initial_size = buf.size();
size_t size = this->serialize_size(); size_t size = this->serialize_size();
if (size == -1) { if (size == -1) {
+2 -1
View File
@@ -7,10 +7,11 @@
#define EXPANDER_DEVICE_NAME_MAX_LEN 32 #define EXPANDER_DEVICE_NAME_MAX_LEN 32
/// The packet type for `BBNowPubPacket`s. /// The packet type for `BBNowPrivPacket`s.
enum class BBNowPrivPacketType: uint16_t { enum class BBNowPrivPacketType: uint16_t {
NONE = 0, NONE = 0,
ACK = 1, ACK = 1,
// TODO: we will need to add more here for handshaking in the future.
DISCOVERY_RESPONSE = 2, DISCOVERY_RESPONSE = 2,
EXPANDER_MESSAGE = 3, EXPANDER_MESSAGE = 3,
MAX = 3, MAX = 3,
+4 -3
View File
@@ -36,6 +36,7 @@ union BlkBoxNowPubPacketData {
}; };
struct BBNowPubPacket { struct BBNowPubPacket {
// "bbnp" in ascii
const static uint32_t PUB_MAGIC_NUMBER = 0x6262'6E70; const static uint32_t PUB_MAGIC_NUMBER = 0x6262'6E70;
// DISCOVERY packet size // DISCOVERY packet size
const static size_t DISCOVERY_PACKET_SIZE = sizeof(PUB_MAGIC_NUMBER) + sizeof(BBNowPubPacketType) + sizeof(BlkBoxNowPubDiscoveryData); const static size_t DISCOVERY_PACKET_SIZE = sizeof(PUB_MAGIC_NUMBER) + sizeof(BBNowPubPacketType) + sizeof(BlkBoxNowPubDiscoveryData);
@@ -47,13 +48,13 @@ struct BBNowPubPacket {
BlkBoxNowPubPacketData packet_data{}; BlkBoxNowPubPacketData packet_data{};
/// The size of the serialized packet (in bytes). /// The size of the serialized packet (in bytes).
size_t serialize_size(); size_t serialize_size() const;
/// Serializes the packet to a vector. /// Serializes the packet to a vector.
std::vector<uint8_t> serialize(); std::vector<uint8_t> serialize() const;
/// Serializes the packet into the given vector. /// Serializes the packet into the given vector.
/// ///
/// Returns the number of bytes written into the buffer. /// Returns the number of bytes written into the buffer.
size_t serialize_into(std::vector<uint8_t>& buf); size_t serialize_into(std::vector<uint8_t>& buf) const;
/// Deserializes a packet from the given bytes. /// Deserializes a packet from the given bytes.
static std::optional<BBNowPubPacket> deserialize(std::span<const uint8_t> bytes); static std::optional<BBNowPubPacket> deserialize(std::span<const uint8_t> bytes);