From 1ac2a73267850190bcce17d08d77cd639bd876b3 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 8 Apr 2026 23:25:12 -1000 Subject: [PATCH] Remove redundant body_start variable in inline encode --- esphome/components/api/api_pb2.cpp | 3 +-- script/api_protobuf/api_protobuf.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/esphome/components/api/api_pb2.cpp b/esphome/components/api/api_pb2.cpp index a33604e6652..6db5dcf97ed 100644 --- a/esphome/components/api/api_pb2.cpp +++ b/esphome/components/api/api_pb2.cpp @@ -2334,7 +2334,6 @@ uint8_t *BluetoothLERawAdvertisementsResponse::encode(ProtoWriteBuffer &buffer P auto &sub_msg = this->advertisements[i]; ProtoEncode::write_raw_byte(pos PROTO_ENCODE_DEBUG_ARG, 10); uint8_t *len_pos = pos++; - uint8_t *body_start = pos; ProtoEncode::write_raw_byte(pos PROTO_ENCODE_DEBUG_ARG, 8); ProtoEncode::encode_varint_raw_64(pos PROTO_ENCODE_DEBUG_ARG, sub_msg.address); ProtoEncode::write_raw_byte(pos PROTO_ENCODE_DEBUG_ARG, 16); @@ -2346,7 +2345,7 @@ uint8_t *BluetoothLERawAdvertisementsResponse::encode(ProtoWriteBuffer &buffer P ProtoEncode::write_raw_byte(pos PROTO_ENCODE_DEBUG_ARG, 34); ProtoEncode::write_raw_byte(pos PROTO_ENCODE_DEBUG_ARG, static_cast(sub_msg.data_len)); ProtoEncode::encode_raw(pos PROTO_ENCODE_DEBUG_ARG, sub_msg.data, sub_msg.data_len); - *len_pos = static_cast(pos - body_start); + *len_pos = static_cast(pos - len_pos - 1); } return pos; } diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index e5b3f773e7c..6f92e4cb6df 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -1596,7 +1596,6 @@ def _generate_inline_encode_block( lines.append(f"auto &sub_msg = {element};") lines.append(f"ProtoEncode::write_raw_byte(pos, {tag});") lines.append("uint8_t *len_pos = pos++;") - lines.append("uint8_t *body_start = pos;") # Generate inline field encoding for each sub-message field for field in sub_desc.field: @@ -1608,7 +1607,7 @@ def _generate_inline_encode_block( encode_line = encode_line.replace("this->", "sub_msg.") lines.extend(encode_line.split("\n")) - lines.append("*len_pos = static_cast(pos - body_start);") + lines.append("*len_pos = static_cast(pos - len_pos - 1);") return "\n".join(lines)