mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 22:53:59 +00:00 
			
		
		
		
	Merge branch 'source_server' into memory_api
This commit is contained in:
		| @@ -1005,6 +1005,11 @@ def build_message_type( | ||||
|     # Get message ID if it's a service message | ||||
|     message_id: int | None = get_opt(desc, pb.id) | ||||
|  | ||||
|     # Get source direction to determine if we need decode/encode methods | ||||
|     source: int = get_opt(desc, pb.source, SOURCE_BOTH) | ||||
|     needs_decode = source in (SOURCE_BOTH, SOURCE_CLIENT) | ||||
|     needs_encode = source in (SOURCE_BOTH, SOURCE_SERVER) | ||||
|  | ||||
|     # Add MESSAGE_TYPE method if this is a service message | ||||
|     if message_id is not None: | ||||
|         # Validate that message_id fits in uint8_t | ||||
| @@ -1047,18 +1052,21 @@ def build_message_type( | ||||
|             protected_content.extend(ti.protected_content) | ||||
|             public_content.extend(ti.public_content) | ||||
|  | ||||
|         # Always include encode/decode logic for all fields | ||||
|         encode.append(ti.encode_content) | ||||
|         size_calc.append(ti.get_size_calculation(f"this->{ti.field_name}")) | ||||
|         # Only collect encode logic if this message needs it | ||||
|         if needs_encode: | ||||
|             encode.append(ti.encode_content) | ||||
|             size_calc.append(ti.get_size_calculation(f"this->{ti.field_name}")) | ||||
|  | ||||
|         if ti.decode_varint_content: | ||||
|             decode_varint.append(ti.decode_varint_content) | ||||
|         if ti.decode_length_content: | ||||
|             decode_length.append(ti.decode_length_content) | ||||
|         if ti.decode_32bit_content: | ||||
|             decode_32bit.append(ti.decode_32bit_content) | ||||
|         if ti.decode_64bit_content: | ||||
|             decode_64bit.append(ti.decode_64bit_content) | ||||
|         # Only collect decode methods if this message needs them | ||||
|         if needs_decode: | ||||
|             if ti.decode_varint_content: | ||||
|                 decode_varint.append(ti.decode_varint_content) | ||||
|             if ti.decode_length_content: | ||||
|                 decode_length.append(ti.decode_length_content) | ||||
|             if ti.decode_32bit_content: | ||||
|                 decode_32bit.append(ti.decode_32bit_content) | ||||
|             if ti.decode_64bit_content: | ||||
|                 decode_64bit.append(ti.decode_64bit_content) | ||||
|         if ti.dump_content: | ||||
|             dump.append(ti.dump_content) | ||||
|  | ||||
| @@ -1108,8 +1116,8 @@ def build_message_type( | ||||
|         prot = "bool decode_64bit(uint32_t field_id, Proto64Bit value) override;" | ||||
|         protected_content.insert(0, prot) | ||||
|  | ||||
|     # Only generate encode method if there are fields to encode | ||||
|     if encode: | ||||
|     # Only generate encode method if this message needs encoding and has fields | ||||
|     if needs_encode and encode: | ||||
|         o = f"void {desc.name}::encode(ProtoWriteBuffer buffer) const {{" | ||||
|         if len(encode) == 1 and len(encode[0]) + len(o) + 3 < 120: | ||||
|             o += f" {encode[0]} " | ||||
| @@ -1120,10 +1128,10 @@ def build_message_type( | ||||
|         cpp += o | ||||
|         prot = "void encode(ProtoWriteBuffer buffer) const override;" | ||||
|         public_content.append(prot) | ||||
|     # If no fields to encode, the default implementation in ProtoMessage will be used | ||||
|     # If no fields to encode or message doesn't need encoding, the default implementation in ProtoMessage will be used | ||||
|  | ||||
|     # Add calculate_size method only if there are fields | ||||
|     if size_calc: | ||||
|     # Add calculate_size method only if this message needs encoding and has fields | ||||
|     if needs_encode and size_calc: | ||||
|         o = f"void {desc.name}::calculate_size(uint32_t &total_size) const {{" | ||||
|         # For a single field, just inline it for simplicity | ||||
|         if len(size_calc) == 1 and len(size_calc[0]) + len(o) + 3 < 120: | ||||
| @@ -1136,7 +1144,7 @@ def build_message_type( | ||||
|         cpp += o | ||||
|         prot = "void calculate_size(uint32_t &total_size) const override;" | ||||
|         public_content.append(prot) | ||||
|     # If no fields to calculate size for, the default implementation in ProtoMessage will be used | ||||
|     # If no fields to calculate size for or message doesn't need encoding, the default implementation in ProtoMessage will be used | ||||
|  | ||||
|     # dump_to method declaration in header | ||||
|     prot = "#ifdef HAS_PROTO_MESSAGE_DUMP\n" | ||||
| @@ -1401,7 +1409,6 @@ def main() -> None: | ||||
| #include "esphome/core/defines.h" | ||||
|  | ||||
| #include "proto.h" | ||||
| #include "api_pb2_size.h" | ||||
|  | ||||
| namespace esphome { | ||||
| namespace api { | ||||
| @@ -1411,7 +1418,6 @@ namespace api { | ||||
|     cpp = FILE_HEADER | ||||
|     cpp += """\ | ||||
|     #include "api_pb2.h" | ||||
|     #include "api_pb2_size.h" | ||||
|     #include "esphome/core/log.h" | ||||
|     #include "esphome/core/helpers.h" | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user