[packet_interface] Use a local to_vector() in tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
clydebarrow
2026-10-20 09:35:39 +11:00
co-authored by Claude Opus 5.5
parent 6c36da4e84
commit b8795fcd33
@@ -14,6 +14,13 @@
namespace esphome::tcp::testing {
// Copies a packet into a vector, for comparing in tests
static std::vector<uint8_t> to_vector(const esphome::packet_interface::PacketBuffer &data) {
std::vector<uint8_t> result(data.size());
data.copy_to(result.data(), result.size());
return result;
}
using packet_interface::PacketBuffer;
using packet_interface::PacketMetaData;
using Packet = std::vector<uint8_t>;
@@ -38,7 +45,7 @@ class UpperLayer : public packet_interface::PacketInterface {
struct End {
End() {
this->link.add_packet_interface_listener(
[this](const PacketBuffer &data, const PacketMetaData &) { this->received.push_back(data.to_vector()); });
[this](const PacketBuffer &data, const PacketMetaData &) { this->received.push_back(to_vector(data)); });
this->link.add_on_session_state_callback([this](bool connected) { this->states.push_back(connected); });
this->link.setup();
}