tweak bbnow types
This commit is contained in:
+3
-3
@@ -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<uint8_t> BBNowPubPacket::serialize() {
|
||||
std::vector<uint8_t> BBNowPubPacket::serialize() const {
|
||||
auto buf = std::vector<uint8_t>();
|
||||
|
||||
if (this->serialize_size() == -1) {
|
||||
@@ -25,7 +25,7 @@ std::vector<uint8_t> BBNowPubPacket::serialize() {
|
||||
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 size = this->serialize_size();
|
||||
if (size == -1) {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<uint8_t> serialize();
|
||||
std::vector<uint8_t> serialize() const;
|
||||
/// Serializes the packet into the given vector.
|
||||
///
|
||||
/// 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.
|
||||
static std::optional<BBNowPubPacket> deserialize(std::span<const uint8_t> bytes);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user