diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 0088e5c451..536a3536db 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -105,7 +105,9 @@ class ProtoVarInt { /// Parse a varint from buffer. consumed must be a valid pointer (not null). static optional 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