Fixes from code review

This commit is contained in:
clydebarrow
2026-10-19 14:40:08 +11:00
parent 95f972d3c5
commit cedafa5208
3 changed files with 9 additions and 20 deletions
@@ -44,8 +44,8 @@ class PacketMetaData {
*
* The operations defined are:
*
* Transmit: the function transmit() takes a PacketBuffer of bytes, and returns when all bytes are queued for
* transmission at least.
* Transmit: the function send_to_interface() takes a PacketBuffer of bytes, and returns when all data is
* written or buffered for transmission.
*
* Receive: The callbacks for an instance of this class are called with currently received data.
*/
@@ -119,7 +119,7 @@ class PacketInterface : public Component {
lower->upper_ = this;
this->inherit_from_(lower, capability);
}
/// Takes the name and capabilities of \p lower without becoming its top, for one of several stacks on a link.
/// Takes the name and capabilities of `lower` without becoming its top, for one of several stacks on a link.
void inherit_from_(PacketInterface *lower, Capability capability) {
this->name_ = lower->name_;
this->capabilities_ = lower->capabilities_ | capability;
@@ -13,19 +13,12 @@ void PacketInterfaceTransport::setup() {
}
void PacketInterfaceTransport::receive_(const PacketBuffer &data) {
if (data.is_contiguous()) {
this->process_(data.as_span());
// Packet interface layers deliver packets in one piece
if (!data.is_contiguous()) {
ESP_LOGW(TAG, "Packet split across buffers is not supported");
return;
}
size_t max_size = this->interface_->get_max_packet_size();
if (data.size() > max_size) {
ESP_LOGW(TAG, "Received packet of %zu bytes is larger than %zu", data.size(), max_size);
return;
}
if (!this->rx_copy_)
this->rx_copy_ = std::make_unique<uint8_t[]>(max_size);
size_t len = data.copy_to(this->rx_copy_.get(), max_size);
this->process_(std::span<const uint8_t>(this->rx_copy_.get(), len));
this->process_(data.as_span());
}
void PacketInterfaceTransport::send_packet(const std::vector<uint8_t> &buf) const {
@@ -3,9 +3,7 @@
#include <cstdint>
#include "esphome/components/packet_interface/packet_buffer.h"
namespace esphome {
namespace packet_interface {
namespace testing {
namespace esphome::packet_interface::testing {
// Test default constructor
TEST(PacketBufferTest, DefaultConstructor) {
@@ -243,6 +241,4 @@ TEST(PacketBufferTest, LargeBuffer) {
EXPECT_EQ(buffer[999], 231); // 999 % 256 = 231
}
} // namespace testing
} // namespace packet_interface
} // namespace esphome
} // namespace esphome::packet_interface::testing