mirror of
https://github.com/esphome/esphome.git
synced 2026-10-02 09:20:22 +00:00
[api] Make generated encode and size entry points type erased
Every message sent through send_message or the entity paths needed a proto_encode_msg<T> thunk (17 bytes on xtensa) and, for entity state and info messages, a calc_size<T> thunk, because the generated encode and calculate_size were member functions and the connection code wants plain function pointers over const void *. The generator now emits the bodies as static encode_msg(const void *) and calc_size_msg(const void *) functions, so &T::encode_msg is already a MessageEncodeFn and the thunks disappear. The member encode() and calculate_size() remain as inline forwarders for direct callers. ProtoMessage carries the same static defaults for messages without fields, which also removes the separate no-op encode thunk.
This commit is contained in:
@@ -194,17 +194,17 @@ def test_superseded_device_info_fields_still_declared_in_header() -> None:
|
||||
|
||||
def test_superseded_device_info_fields_still_encoded_and_sized() -> None:
|
||||
"""Each superseded field must still be touched by DeviceInfoResponse's
|
||||
generated encode() and calculate_size(), i.e. it is still put on the wire.
|
||||
generated encode_msg() and calc_size_msg(), i.e. it is still put on the wire.
|
||||
"""
|
||||
encode_body = _extract_function_body(CPP_TEXT, "DeviceInfoResponse::encode")
|
||||
size_body = _extract_function_body(CPP_TEXT, "DeviceInfoResponse::calculate_size")
|
||||
encode_body = _extract_function_body(CPP_TEXT, "DeviceInfoResponse::encode_msg")
|
||||
size_body = _extract_function_body(CPP_TEXT, "DeviceInfoResponse::calc_size_msg")
|
||||
for field_name in SUPERSEDED_FIELDS:
|
||||
assert f"this->{field_name}" in encode_body, (
|
||||
f"DeviceInfoResponse::encode() no longer references {field_name}. "
|
||||
assert f"msg.{field_name}" in encode_body, (
|
||||
f"DeviceInfoResponse::encode_msg() no longer references {field_name}. "
|
||||
f"{DEPRECATED_FIELD_TRAP}"
|
||||
)
|
||||
assert f"this->{field_name}" in size_body, (
|
||||
f"DeviceInfoResponse::calculate_size() no longer references "
|
||||
assert f"msg.{field_name}" in size_body, (
|
||||
f"DeviceInfoResponse::calc_size_msg() no longer references "
|
||||
f"{field_name}. {DEPRECATED_FIELD_TRAP}"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user