Guard asserts with ESPHOME_DEBUG_API to avoid flash overhead

This commit is contained in:
J. Nick Koston
2026-02-11 11:18:50 -06:00
parent fb1c495506
commit 77d8fc80be

View File

@@ -105,7 +105,9 @@ class ProtoVarInt {
/// Parse a varint from buffer. consumed must be a valid pointer (not null).
static optional<ProtoVarInt> parse(const uint8_t *buffer, uint32_t len, uint32_t *consumed) {
#ifdef ESPHOME_DEBUG_API
assert(consumed != nullptr);
#endif
if (len == 0)
return {};
@@ -920,8 +922,10 @@ inline void ProtoWriteBuffer::encode_message(uint32_t field_id, const ProtoMessa
// Now encode the message content - it will append to the buffer
value.encode(*this);
#ifdef ESPHOME_DEBUG_API
// Verify that the encoded size matches what we calculated
assert(this->buffer_->size() == begin + varint_length_bytes + msg_length_bytes);
#endif
}
// Implementation of decode_to_message - must be after ProtoDecodableMessage is defined