mirror of
https://github.com/esphome/esphome.git
synced 2026-09-01 10:36:01 +00:00
[api] Replace empty messages check with debug assert
Callers are responsible for not passing empty spans. Added ESPHOME_DEBUG_API assert to catch bugs during development.
This commit is contained in:
@@ -163,9 +163,10 @@ class APIFrameHelper {
|
||||
}
|
||||
// Write a single protobuf message - the hot path (87-100% of all writes)
|
||||
virtual APIError write_protobuf_packet(uint8_t type, ProtoWriteBuffer buffer) = 0;
|
||||
// Write multiple protobuf messages in a single batched operation
|
||||
// messages contains (message_type, offset, length) for each message in the buffer
|
||||
// The buffer contains all messages with appropriate padding before each
|
||||
// Write multiple protobuf messages in a single batched operation.
|
||||
// messages must not be empty — caller is responsible for checking.
|
||||
// messages contains (message_type, offset, length) for each message in the buffer.
|
||||
// The buffer contains all messages with appropriate padding before each.
|
||||
virtual APIError write_protobuf_messages(ProtoWriteBuffer buffer, std::span<const MessageInfo> messages) = 0;
|
||||
// Get the frame header padding required by this protocol
|
||||
uint8_t frame_header_padding() const { return frame_header_padding_; }
|
||||
|
||||
@@ -511,10 +511,9 @@ APIError APINoiseFrameHelper::write_protobuf_messages(ProtoWriteBuffer buffer, s
|
||||
APIError aerr = this->check_data_state_();
|
||||
if (aerr != APIError::OK)
|
||||
return aerr;
|
||||
|
||||
if (messages.empty()) {
|
||||
return APIError::OK;
|
||||
}
|
||||
#ifdef ESPHOME_DEBUG_API
|
||||
assert(!messages.empty());
|
||||
#endif
|
||||
|
||||
uint8_t *buffer_data = buffer.get_buffer()->data();
|
||||
StaticVector<struct iovec, MAX_MESSAGES_PER_BATCH> iovs;
|
||||
|
||||
@@ -302,10 +302,9 @@ APIError APIPlaintextFrameHelper::write_protobuf_messages(ProtoWriteBuffer buffe
|
||||
APIError aerr = this->check_data_state_();
|
||||
if (aerr != APIError::OK)
|
||||
return aerr;
|
||||
|
||||
if (messages.empty()) {
|
||||
return APIError::OK;
|
||||
}
|
||||
#ifdef ESPHOME_DEBUG_API
|
||||
assert(!messages.empty());
|
||||
#endif
|
||||
|
||||
uint8_t *buffer_data = buffer.get_buffer()->data();
|
||||
StaticVector<struct iovec, MAX_MESSAGES_PER_BATCH> iovs;
|
||||
|
||||
Reference in New Issue
Block a user