[api] Make ProtoDecodableMessage::decode() non-virtual

decode() is never called polymorphically - all call sites in
read_message_() use concrete types. The only indirect call site was
decode_to_message(), which also always knows the concrete type.

Convert decode_to_message() to a template so the concrete type is
preserved, allowing decode() to be non-virtual. The two classes that
override decode() (ExecuteServiceArgument, ExecuteServiceRequest) now
hide the base method, which works since all calls use concrete types.

This removes one vtable slot (4 bytes) from each decodable message
class vtable, saving ~148 bytes of flash.
This commit is contained in:
J. Nick Koston
2026-03-21 20:51:28 -10:00
parent 1d191d2461
commit a5bd718fc9
3 changed files with 10 additions and 18 deletions
+1 -1
View File
@@ -2262,7 +2262,7 @@ def build_message_type(
o += "}\n"
cpp += o
# Generate the decode() declaration in header (public method)
prot = "void decode(const uint8_t *buffer, size_t length) override;"
prot = "void decode(const uint8_t *buffer, size_t length);"
public_content.append(prot)
# Only generate encode method if this message needs encoding and has fields