mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	dry
This commit is contained in:
		| @@ -504,18 +504,8 @@ class ProtoSize { | |||||||
|    * @brief Calculates and adds the size of an int32 field to the total message size |    * @brief Calculates and adds the size of an int32 field to the total message size | ||||||
|    */ |    */ | ||||||
|   inline void add_int32(uint32_t field_id_size, int32_t value) { |   inline void add_int32(uint32_t field_id_size, int32_t value) { | ||||||
|     // Skip calculation if value is zero |     if (value != 0) { | ||||||
|     if (value == 0) { |       add_int32_force(field_id_size, value); | ||||||
|       return;  // No need to update total_size_ |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     // Calculate and directly add to total_size |  | ||||||
|     if (value < 0) { |  | ||||||
|       // Negative values are encoded as 10-byte varints in protobuf |  | ||||||
|       total_size_ += field_id_size + 10; |  | ||||||
|     } else { |  | ||||||
|       // For non-negative values, use the standard varint size |  | ||||||
|       total_size_ += field_id_size + varint(static_cast<uint32_t>(value)); |  | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
| @@ -554,14 +544,11 @@ class ProtoSize { | |||||||
|    * @brief Calculates and adds the size of a boolean field to the total message size |    * @brief Calculates and adds the size of a boolean field to the total message size | ||||||
|    */ |    */ | ||||||
|   inline void add_bool(uint32_t field_id_size, bool value) { |   inline void add_bool(uint32_t field_id_size, bool value) { | ||||||
|     // Skip calculation if value is false |     if (value) { | ||||||
|     if (!value) { |  | ||||||
|       return;  // No need to update total_size_ |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|       // Boolean fields always use 1 byte when true |       // Boolean fields always use 1 byte when true | ||||||
|       total_size_ += field_id_size + 1; |       total_size_ += field_id_size + 1; | ||||||
|     } |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @brief Calculates and adds the size of a boolean field to the total message size (force version) |    * @brief Calculates and adds the size of a boolean field to the total message size (force version) | ||||||
| @@ -706,15 +693,11 @@ class ProtoSize { | |||||||
|    * @param nested_size The pre-calculated size of the nested message |    * @param nested_size The pre-calculated size of the nested message | ||||||
|    */ |    */ | ||||||
|   inline void add_message_field(uint32_t field_id_size, uint32_t nested_size) { |   inline void add_message_field(uint32_t field_id_size, uint32_t nested_size) { | ||||||
|     // Skip calculation if nested message is empty |     if (nested_size != 0) { | ||||||
|     if (nested_size == 0) { |  | ||||||
|       return;  // No need to update total_size_ |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     // Calculate and directly add to total_size |  | ||||||
|       // Field ID + length varint + nested message content |       // Field ID + length varint + nested message content | ||||||
|       total_size_ += field_id_size + varint(nested_size) + nested_size; |       total_size_ += field_id_size + varint(nested_size) + nested_size; | ||||||
|     } |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @brief Calculates and adds the size of a nested message field to the total message size (force version) |    * @brief Calculates and adds the size of a nested message field to the total message size (force version) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user