diff --git a/esphome/components/api/proto.h b/esphome/components/api/proto.h index 86c7b696a5..b77a86ca93 100644 --- a/esphome/components/api/proto.h +++ b/esphome/components/api/proto.h @@ -692,11 +692,8 @@ class DumpBuffer { class ProtoMessage { public: - // Non-virtual defaults for messages with no fields; generated message classes hide all four. - // encode_msg/calc_size_msg are the type-erased entry points (static over const void *), so - // &T::encode_msg is a MessageEncodeFn with no per-type thunk; encode()/calculate_size() serve - // direct callers and forward to the statics in generated classes. No virtual dispatch: every - // call site knows the concrete type, which keeps these out of the per-message vtables. + // Non-virtual defaults for messages with no fields; generated classes hide all four. The + // static encode_msg/calc_size_msg take const void * so &T::encode_msg needs no thunk. static uint8_t *encode_msg(const void *self, ProtoWriteBuffer &buffer PROTO_ENCODE_DEBUG_PARAM) { return buffer.get_pos(); } diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 0131c75484..c919d80295 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -2841,9 +2841,7 @@ def build_message_type( ) for line in encode ] - # The body is a static function taking the message as const void *, so its address is - # already a MessageEncodeFn and callers need no per-type thunk. The member encode() below - # forwards to it for direct callers. + # Static over const void * so &T::encode_msg is a MessageEncodeFn without a thunk. o = f"{speed_attr}uint8_t *{desc.name}::encode_msg(const void *self, ProtoWriteBuffer &buffer PROTO_ENCODE_DEBUG_PARAM) {{\n" o += f" const auto &msg = *static_cast(self);\n" o += " uint8_t *__restrict__ pos = buffer.get_pos();\n"