diff --git a/esphome/components/api/api_pb2.cpp b/esphome/components/api/api_pb2.cpp index a33604e665..6db5dcf97e 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 e5b3f773e7..6f92e4cb6d 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)