From 885a133080e5119cad38a7e7d3963ed6c72fd46b Mon Sep 17 00:00:00 2001 From: Mitchell Date: Thu, 13 Aug 2026 14:23:05 -0500 Subject: [PATCH] tweak bbnow types --- bbnow_pub.cpp | 6 +++--- include/bbnow_priv.hpp | 3 ++- include/bbnow_pub.hpp | 7 ++++--- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bbnow_pub.cpp b/bbnow_pub.cpp index 162c24a..1657a9f 100644 --- a/bbnow_pub.cpp +++ b/bbnow_pub.cpp @@ -4,7 +4,7 @@ const static char TAG[] = "bbnow_pub"; -size_t BBNowPubPacket::serialize_size() { +size_t BBNowPubPacket::serialize_size() const { switch (this->packet_type) { case BBNowPubPacketType::NONE: return -1; @@ -14,7 +14,7 @@ size_t BBNowPubPacket::serialize_size() { return -1; } -std::vector BBNowPubPacket::serialize() { +std::vector BBNowPubPacket::serialize() const { auto buf = std::vector(); if (this->serialize_size() == -1) { @@ -25,7 +25,7 @@ std::vector BBNowPubPacket::serialize() { return buf; } -size_t BBNowPubPacket::serialize_into(std::vector& buf) { +size_t BBNowPubPacket::serialize_into(std::vector& buf) const { size_t initial_size = buf.size(); size_t size = this->serialize_size(); if (size == -1) { diff --git a/include/bbnow_priv.hpp b/include/bbnow_priv.hpp index c8f0684..586ac22 100644 --- a/include/bbnow_priv.hpp +++ b/include/bbnow_priv.hpp @@ -7,10 +7,11 @@ #define EXPANDER_DEVICE_NAME_MAX_LEN 32 -/// The packet type for `BBNowPubPacket`s. +/// The packet type for `BBNowPrivPacket`s. enum class BBNowPrivPacketType: uint16_t { NONE = 0, ACK = 1, + // TODO: we will need to add more here for handshaking in the future. DISCOVERY_RESPONSE = 2, EXPANDER_MESSAGE = 3, MAX = 3, diff --git a/include/bbnow_pub.hpp b/include/bbnow_pub.hpp index 9a7a7e1..2847044 100644 --- a/include/bbnow_pub.hpp +++ b/include/bbnow_pub.hpp @@ -36,6 +36,7 @@ union BlkBoxNowPubPacketData { }; struct BBNowPubPacket { + // "bbnp" in ascii const static uint32_t PUB_MAGIC_NUMBER = 0x6262'6E70; // DISCOVERY packet size const static size_t DISCOVERY_PACKET_SIZE = sizeof(PUB_MAGIC_NUMBER) + sizeof(BBNowPubPacketType) + sizeof(BlkBoxNowPubDiscoveryData); @@ -47,13 +48,13 @@ struct BBNowPubPacket { BlkBoxNowPubPacketData packet_data{}; /// The size of the serialized packet (in bytes). - size_t serialize_size(); + size_t serialize_size() const; /// Serializes the packet to a vector. - std::vector serialize(); + std::vector serialize() const; /// Serializes the packet into the given vector. /// /// Returns the number of bytes written into the buffer. - size_t serialize_into(std::vector& buf); + size_t serialize_into(std::vector& buf) const; /// Deserializes a packet from the given bytes. static std::optional deserialize(std::span bytes);