mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-30 06:33:51 +00:00 
			
		
		
		
	Merge branch 'remove_false' into integration
This commit is contained in:
		
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -141,9 +141,9 @@ 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 | ||||||
|    */ |    */ | ||||||
|   static inline void add_int32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value, bool force = false) { |   static inline void add_int32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value) { | ||||||
|     // Skip calculation if value is zero and not forced |     // Skip calculation if value is zero | ||||||
|     if (value == 0 && !force) { |     if (value == 0) { | ||||||
|       return;  // No need to update total_size |       return;  // No need to update total_size | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -157,13 +157,26 @@ class ProtoSize { | |||||||
|     } |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * @brief Calculates and adds the size of an int32 field to the total message size (repeated field version) | ||||||
|  |    */ | ||||||
|  |   static inline void add_int32_field_repeated(uint32_t &total_size, uint32_t field_id_size, int32_t value) { | ||||||
|  |     // Always calculate size for repeated fields | ||||||
|  |     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)); | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @brief Calculates and adds the size of a uint32 field to the total message size |    * @brief Calculates and adds the size of a uint32 field to the total message size | ||||||
|    */ |    */ | ||||||
|   static inline void add_uint32_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value, |   static inline void add_uint32_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { | ||||||
|                                       bool force = false) { |     // Skip calculation if value is zero | ||||||
|     // Skip calculation if value is zero and not forced |     if (value == 0) { | ||||||
|     if (value == 0 && !force) { |  | ||||||
|       return;  // No need to update total_size |       return;  // No need to update total_size | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -171,12 +184,20 @@ class ProtoSize { | |||||||
|     total_size += field_id_size + varint(value); |     total_size += field_id_size + varint(value); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * @brief Calculates and adds the size of a uint32 field to the total message size (repeated field version) | ||||||
|  |    */ | ||||||
|  |   static inline void add_uint32_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { | ||||||
|  |     // Always calculate size for repeated fields | ||||||
|  |     total_size += field_id_size + varint(value); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @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 | ||||||
|    */ |    */ | ||||||
|   static inline void add_bool_field(uint32_t &total_size, uint32_t field_id_size, bool value, bool force = false) { |   static inline void add_bool_field(uint32_t &total_size, uint32_t field_id_size, bool value) { | ||||||
|     // Skip calculation if value is false and not forced |     // Skip calculation if value is false | ||||||
|     if (!value && !force) { |     if (!value) { | ||||||
|       return;  // No need to update total_size |       return;  // No need to update total_size | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -184,6 +205,15 @@ class ProtoSize { | |||||||
|     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 (repeated field version) | ||||||
|  |    */ | ||||||
|  |   static inline void add_bool_field_repeated(uint32_t &total_size, uint32_t field_id_size, bool value) { | ||||||
|  |     // Always calculate size for repeated fields | ||||||
|  |     // Boolean fields always use 1 byte | ||||||
|  |     total_size += field_id_size + 1; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @brief Calculates and adds the size of a fixed field to the total message size |    * @brief Calculates and adds the size of a fixed field to the total message size | ||||||
|    * |    * | ||||||
| @@ -193,10 +223,9 @@ class ProtoSize { | |||||||
|    * @param is_nonzero Whether the value is non-zero |    * @param is_nonzero Whether the value is non-zero | ||||||
|    */ |    */ | ||||||
|   template<uint32_t NumBytes> |   template<uint32_t NumBytes> | ||||||
|   static inline void add_fixed_field(uint32_t &total_size, uint32_t field_id_size, bool is_nonzero, |   static inline void add_fixed_field(uint32_t &total_size, uint32_t field_id_size, bool is_nonzero) { | ||||||
|                                      bool force = false) { |     // Skip calculation if value is zero | ||||||
|     // Skip calculation if value is zero and not forced |     if (!is_nonzero) { | ||||||
|     if (!is_nonzero && !force) { |  | ||||||
|       return;  // No need to update total_size |       return;  // No need to update total_size | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -204,14 +233,26 @@ class ProtoSize { | |||||||
|     total_size += field_id_size + NumBytes; |     total_size += field_id_size + NumBytes; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * @brief Calculates and adds the size of a fixed field to the total message size (repeated field version) | ||||||
|  |    * | ||||||
|  |    * @tparam NumBytes The number of bytes for this fixed field (4 or 8) | ||||||
|  |    */ | ||||||
|  |   template<uint32_t NumBytes> | ||||||
|  |   static inline void add_fixed_field_repeated(uint32_t &total_size, uint32_t field_id_size) { | ||||||
|  |     // Always calculate size for repeated fields | ||||||
|  |     // Fixed fields always take exactly NumBytes | ||||||
|  |     total_size += field_id_size + NumBytes; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @brief Calculates and adds the size of an enum field to the total message size |    * @brief Calculates and adds the size of an enum field to the total message size | ||||||
|    * |    * | ||||||
|    * Enum fields are encoded as uint32 varints. |    * Enum fields are encoded as uint32 varints. | ||||||
|    */ |    */ | ||||||
|   static inline void add_enum_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value, bool force = false) { |   static inline void add_enum_field(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { | ||||||
|     // Skip calculation if value is zero and not forced |     // Skip calculation if value is zero | ||||||
|     if (value == 0 && !force) { |     if (value == 0) { | ||||||
|       return;  // No need to update total_size |       return;  // No need to update total_size | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -219,14 +260,25 @@ class ProtoSize { | |||||||
|     total_size += field_id_size + varint(value); |     total_size += field_id_size + varint(value); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * @brief Calculates and adds the size of an enum field to the total message size (repeated field version) | ||||||
|  |    * | ||||||
|  |    * Enum fields are encoded as uint32 varints. | ||||||
|  |    */ | ||||||
|  |   static inline void add_enum_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint32_t value) { | ||||||
|  |     // Always calculate size for repeated fields | ||||||
|  |     // Enums are encoded as uint32 | ||||||
|  |     total_size += field_id_size + varint(value); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @brief Calculates and adds the size of a sint32 field to the total message size |    * @brief Calculates and adds the size of a sint32 field to the total message size | ||||||
|    * |    * | ||||||
|    * Sint32 fields use ZigZag encoding, which is more efficient for negative values. |    * Sint32 fields use ZigZag encoding, which is more efficient for negative values. | ||||||
|    */ |    */ | ||||||
|   static inline void add_sint32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value, bool force = false) { |   static inline void add_sint32_field(uint32_t &total_size, uint32_t field_id_size, int32_t value) { | ||||||
|     // Skip calculation if value is zero and not forced |     // Skip calculation if value is zero | ||||||
|     if (value == 0 && !force) { |     if (value == 0) { | ||||||
|       return;  // No need to update total_size |       return;  // No need to update total_size | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -235,12 +287,24 @@ class ProtoSize { | |||||||
|     total_size += field_id_size + varint(zigzag); |     total_size += field_id_size + varint(zigzag); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * @brief Calculates and adds the size of a sint32 field to the total message size (repeated field version) | ||||||
|  |    * | ||||||
|  |    * Sint32 fields use ZigZag encoding, which is more efficient for negative values. | ||||||
|  |    */ | ||||||
|  |   static inline void add_sint32_field_repeated(uint32_t &total_size, uint32_t field_id_size, int32_t value) { | ||||||
|  |     // Always calculate size for repeated fields | ||||||
|  |     // ZigZag encoding for sint32: (n << 1) ^ (n >> 31) | ||||||
|  |     uint32_t zigzag = (static_cast<uint32_t>(value) << 1) ^ (static_cast<uint32_t>(value >> 31)); | ||||||
|  |     total_size += field_id_size + varint(zigzag); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @brief Calculates and adds the size of an int64 field to the total message size |    * @brief Calculates and adds the size of an int64 field to the total message size | ||||||
|    */ |    */ | ||||||
|   static inline void add_int64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value, bool force = false) { |   static inline void add_int64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value) { | ||||||
|     // Skip calculation if value is zero and not forced |     // Skip calculation if value is zero | ||||||
|     if (value == 0 && !force) { |     if (value == 0) { | ||||||
|       return;  // No need to update total_size |       return;  // No need to update total_size | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -248,13 +312,20 @@ class ProtoSize { | |||||||
|     total_size += field_id_size + varint(value); |     total_size += field_id_size + varint(value); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * @brief Calculates and adds the size of an int64 field to the total message size (repeated field version) | ||||||
|  |    */ | ||||||
|  |   static inline void add_int64_field_repeated(uint32_t &total_size, uint32_t field_id_size, int64_t value) { | ||||||
|  |     // Always calculate size for repeated fields | ||||||
|  |     total_size += field_id_size + varint(value); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @brief Calculates and adds the size of a uint64 field to the total message size |    * @brief Calculates and adds the size of a uint64 field to the total message size | ||||||
|    */ |    */ | ||||||
|   static inline void add_uint64_field(uint32_t &total_size, uint32_t field_id_size, uint64_t value, |   static inline void add_uint64_field(uint32_t &total_size, uint32_t field_id_size, uint64_t value) { | ||||||
|                                       bool force = false) { |     // Skip calculation if value is zero | ||||||
|     // Skip calculation if value is zero and not forced |     if (value == 0) { | ||||||
|     if (value == 0 && !force) { |  | ||||||
|       return;  // No need to update total_size |       return;  // No need to update total_size | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -262,14 +333,22 @@ class ProtoSize { | |||||||
|     total_size += field_id_size + varint(value); |     total_size += field_id_size + varint(value); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * @brief Calculates and adds the size of a uint64 field to the total message size (repeated field version) | ||||||
|  |    */ | ||||||
|  |   static inline void add_uint64_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint64_t value) { | ||||||
|  |     // Always calculate size for repeated fields | ||||||
|  |     total_size += field_id_size + varint(value); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @brief Calculates and adds the size of a sint64 field to the total message size |    * @brief Calculates and adds the size of a sint64 field to the total message size | ||||||
|    * |    * | ||||||
|    * Sint64 fields use ZigZag encoding, which is more efficient for negative values. |    * Sint64 fields use ZigZag encoding, which is more efficient for negative values. | ||||||
|    */ |    */ | ||||||
|   static inline void add_sint64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value, bool force = false) { |   static inline void add_sint64_field(uint32_t &total_size, uint32_t field_id_size, int64_t value) { | ||||||
|     // Skip calculation if value is zero and not forced |     // Skip calculation if value is zero | ||||||
|     if (value == 0 && !force) { |     if (value == 0) { | ||||||
|       return;  // No need to update total_size |       return;  // No need to update total_size | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -278,13 +357,24 @@ class ProtoSize { | |||||||
|     total_size += field_id_size + varint(zigzag); |     total_size += field_id_size + varint(zigzag); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * @brief Calculates and adds the size of a sint64 field to the total message size (repeated field version) | ||||||
|  |    * | ||||||
|  |    * Sint64 fields use ZigZag encoding, which is more efficient for negative values. | ||||||
|  |    */ | ||||||
|  |   static inline void add_sint64_field_repeated(uint32_t &total_size, uint32_t field_id_size, int64_t value) { | ||||||
|  |     // Always calculate size for repeated fields | ||||||
|  |     // ZigZag encoding for sint64: (n << 1) ^ (n >> 63) | ||||||
|  |     uint64_t zigzag = (static_cast<uint64_t>(value) << 1) ^ (static_cast<uint64_t>(value >> 63)); | ||||||
|  |     total_size += field_id_size + varint(zigzag); | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @brief Calculates and adds the size of a string/bytes field to the total message size |    * @brief Calculates and adds the size of a string/bytes field to the total message size | ||||||
|    */ |    */ | ||||||
|   static inline void add_string_field(uint32_t &total_size, uint32_t field_id_size, const std::string &str, |   static inline void add_string_field(uint32_t &total_size, uint32_t field_id_size, const std::string &str) { | ||||||
|                                       bool force = false) { |     // Skip calculation if string is empty | ||||||
|     // Skip calculation if string is empty and not forced |     if (str.empty()) { | ||||||
|     if (str.empty() && !force) { |  | ||||||
|       return;  // No need to update total_size |       return;  // No need to update total_size | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -293,18 +383,26 @@ class ProtoSize { | |||||||
|     total_size += field_id_size + varint(str_size) + str_size; |     total_size += field_id_size + varint(str_size) + str_size; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * @brief Calculates and adds the size of a string/bytes field to the total message size (repeated field version) | ||||||
|  |    */ | ||||||
|  |   static inline void add_string_field_repeated(uint32_t &total_size, uint32_t field_id_size, const std::string &str) { | ||||||
|  |     // Always calculate size for repeated fields | ||||||
|  |     const uint32_t str_size = static_cast<uint32_t>(str.size()); | ||||||
|  |     total_size += field_id_size + varint(str_size) + str_size; | ||||||
|  |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
|    * @brief Calculates and adds the size of a nested message field to the total message size |    * @brief Calculates and adds the size of a nested message field to the total message size | ||||||
|    * |    * | ||||||
|    * This helper function directly updates the total_size reference if the nested size |    * This helper function directly updates the total_size reference if the nested size | ||||||
|    * is greater than zero or force is true. |    * is greater than zero. | ||||||
|    * |    * | ||||||
|    * @param nested_size The pre-calculated size of the nested message |    * @param nested_size The pre-calculated size of the nested message | ||||||
|    */ |    */ | ||||||
|   static inline void add_message_field(uint32_t &total_size, uint32_t field_id_size, uint32_t nested_size, |   static inline void add_message_field(uint32_t &total_size, uint32_t field_id_size, uint32_t nested_size) { | ||||||
|                                        bool force = false) { |     // Skip calculation if nested message is empty | ||||||
|     // Skip calculation if nested message is empty and not forced |     if (nested_size == 0) { | ||||||
|     if (nested_size == 0 && !force) { |  | ||||||
|       return;  // No need to update total_size |       return;  // No need to update total_size | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -313,6 +411,17 @@ class ProtoSize { | |||||||
|     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 (repeated field version) | ||||||
|  |    * | ||||||
|  |    * @param nested_size The pre-calculated size of the nested message | ||||||
|  |    */ | ||||||
|  |   static inline void add_message_field_repeated(uint32_t &total_size, uint32_t field_id_size, uint32_t nested_size) { | ||||||
|  |     // Always calculate size for repeated fields | ||||||
|  |     // Field ID + length varint + nested message content | ||||||
|  |     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 |    * @brief Calculates and adds the size of a nested message field to the total message size | ||||||
|    * |    * | ||||||
| @@ -322,13 +431,26 @@ class ProtoSize { | |||||||
|    * |    * | ||||||
|    * @param message The nested message object |    * @param message The nested message object | ||||||
|    */ |    */ | ||||||
|   static inline void add_message_object(uint32_t &total_size, uint32_t field_id_size, const ProtoMessage &message, |   static inline void add_message_object(uint32_t &total_size, uint32_t field_id_size, const ProtoMessage &message) { | ||||||
|                                         bool force = false) { |  | ||||||
|     uint32_t nested_size = 0; |     uint32_t nested_size = 0; | ||||||
|     message.calculate_size(nested_size); |     message.calculate_size(nested_size); | ||||||
|  |  | ||||||
|     // Use the base implementation with the calculated nested_size |     // Use the base implementation with the calculated nested_size | ||||||
|     add_message_field(total_size, field_id_size, nested_size, force); |     add_message_field(total_size, field_id_size, nested_size); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  |   /** | ||||||
|  |    * @brief Calculates and adds the size of a nested message field to the total message size (repeated field version) | ||||||
|  |    * | ||||||
|  |    * @param message The nested message object | ||||||
|  |    */ | ||||||
|  |   static inline void add_message_object_repeated(uint32_t &total_size, uint32_t field_id_size, | ||||||
|  |                                                  const ProtoMessage &message) { | ||||||
|  |     uint32_t nested_size = 0; | ||||||
|  |     message.calculate_size(nested_size); | ||||||
|  |  | ||||||
|  |     // Use the base implementation with the calculated nested_size | ||||||
|  |     add_message_field_repeated(total_size, field_id_size, nested_size); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   /** |   /** | ||||||
| @@ -348,9 +470,9 @@ class ProtoSize { | |||||||
|       return; |       return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     // For repeated fields, always use force=true |     // Use the repeated field version for all messages | ||||||
|     for (const auto &message : messages) { |     for (const auto &message : messages) { | ||||||
|       add_message_object(total_size, field_id_size, message, true); |       add_message_object_repeated(total_size, field_id_size, message); | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
| }; | }; | ||||||
|   | |||||||
| @@ -249,6 +249,44 @@ class TypeInfo(ABC): | |||||||
|             return 4  # 28 bits |             return 4  # 28 bits | ||||||
|         return 5  # 32 bits (maximum for uint32_t) |         return 5  # 32 bits (maximum for uint32_t) | ||||||
|  |  | ||||||
|  |     def _get_simple_size_calculation( | ||||||
|  |         self, name: str, force: bool, base_method: str, value_expr: str = None | ||||||
|  |     ) -> str: | ||||||
|  |         """Helper for simple size calculations. | ||||||
|  |  | ||||||
|  |         Args: | ||||||
|  |             name: Field name | ||||||
|  |             force: Whether this is for a repeated field | ||||||
|  |             base_method: Base method name (e.g., "add_int32_field") | ||||||
|  |             value_expr: Optional value expression (defaults to name) | ||||||
|  |         """ | ||||||
|  |         field_id_size = self.calculate_field_id_size() | ||||||
|  |         method = f"{base_method}_repeated" if force else base_method | ||||||
|  |         value = value_expr if value_expr else name | ||||||
|  |         return f"ProtoSize::{method}(total_size, {field_id_size}, {value});" | ||||||
|  |  | ||||||
|  |     def _get_fixed_size_calculation( | ||||||
|  |         self, name: str, force: bool, num_bytes: int, zero_check: str | ||||||
|  |     ) -> str: | ||||||
|  |         """Helper for fixed-size field calculations. | ||||||
|  |  | ||||||
|  |         Args: | ||||||
|  |             name: Field name | ||||||
|  |             force: Whether this is for a repeated field | ||||||
|  |             num_bytes: Number of bytes (4 or 8) | ||||||
|  |             zero_check: Expression to check for zero value (e.g., "!= 0.0f") | ||||||
|  |         """ | ||||||
|  |         field_id_size = self.calculate_field_id_size() | ||||||
|  |         method = ( | ||||||
|  |             f"add_fixed_field_repeated<{num_bytes}>" | ||||||
|  |             if force | ||||||
|  |             else f"add_fixed_field<{num_bytes}>" | ||||||
|  |         ) | ||||||
|  |         if force: | ||||||
|  |             return f"ProtoSize::{method}(total_size, {field_id_size});" | ||||||
|  |         else: | ||||||
|  |             return f"ProtoSize::{method}(total_size, {field_id_size}, {name} {zero_check});" | ||||||
|  |  | ||||||
|     @abstractmethod |     @abstractmethod | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         """Calculate the size needed for encoding this field. |         """Calculate the size needed for encoding this field. | ||||||
| @@ -295,9 +333,7 @@ class DoubleType(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_fixed_size_calculation(name, force, 8, "!= 0.0") | ||||||
|         o = f"ProtoSize::add_fixed_field<8>(total_size, {field_id_size}, {name} != 0.0, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 8  # field ID + 8 bytes for double |         return self.calculate_field_id_size() + 8  # field ID + 8 bytes for double | ||||||
| @@ -317,9 +353,7 @@ class FloatType(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_fixed_size_calculation(name, force, 4, "!= 0.0f") | ||||||
|         o = f"ProtoSize::add_fixed_field<4>(total_size, {field_id_size}, {name} != 0.0f, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 4  # field ID + 4 bytes for float |         return self.calculate_field_id_size() + 4  # field ID + 4 bytes for float | ||||||
| @@ -339,9 +373,7 @@ class Int64Type(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_simple_size_calculation(name, force, "add_int64_field") | ||||||
|         o = f"ProtoSize::add_int64_field(total_size, {field_id_size}, {name}, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 3  # field ID + 3 bytes typical varint |         return self.calculate_field_id_size() + 3  # field ID + 3 bytes typical varint | ||||||
| @@ -361,9 +393,7 @@ class UInt64Type(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_simple_size_calculation(name, force, "add_uint64_field") | ||||||
|         o = f"ProtoSize::add_uint64_field(total_size, {field_id_size}, {name}, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 3  # field ID + 3 bytes typical varint |         return self.calculate_field_id_size() + 3  # field ID + 3 bytes typical varint | ||||||
| @@ -383,9 +413,7 @@ class Int32Type(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_simple_size_calculation(name, force, "add_int32_field") | ||||||
|         o = f"ProtoSize::add_int32_field(total_size, {field_id_size}, {name}, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 3  # field ID + 3 bytes typical varint |         return self.calculate_field_id_size() + 3  # field ID + 3 bytes typical varint | ||||||
| @@ -405,9 +433,7 @@ class Fixed64Type(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_fixed_size_calculation(name, force, 8, "!= 0") | ||||||
|         o = f"ProtoSize::add_fixed_field<8>(total_size, {field_id_size}, {name} != 0, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 8  # field ID + 8 bytes fixed |         return self.calculate_field_id_size() + 8  # field ID + 8 bytes fixed | ||||||
| @@ -427,9 +453,7 @@ class Fixed32Type(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_fixed_size_calculation(name, force, 4, "!= 0") | ||||||
|         o = f"ProtoSize::add_fixed_field<4>(total_size, {field_id_size}, {name} != 0, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 4  # field ID + 4 bytes fixed |         return self.calculate_field_id_size() + 4  # field ID + 4 bytes fixed | ||||||
| @@ -448,9 +472,7 @@ class BoolType(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_simple_size_calculation(name, force, "add_bool_field") | ||||||
|         o = f"ProtoSize::add_bool_field(total_size, {field_id_size}, {name}, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 1  # field ID + 1 byte |         return self.calculate_field_id_size() + 1  # field ID + 1 byte | ||||||
| @@ -471,9 +493,7 @@ class StringType(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_simple_size_calculation(name, force, "add_string_field") | ||||||
|         o = f"ProtoSize::add_string_field(total_size, {field_id_size}, {name}, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 8  # field ID + 8 bytes typical string |         return self.calculate_field_id_size() + 8  # field ID + 8 bytes typical string | ||||||
| @@ -509,9 +529,7 @@ class MessageType(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_simple_size_calculation(name, force, "add_message_object") | ||||||
|         o = f"ProtoSize::add_message_object(total_size, {field_id_size}, {name}, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return ( |         return ( | ||||||
| @@ -538,9 +556,7 @@ class BytesType(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_simple_size_calculation(name, force, "add_string_field") | ||||||
|         o = f"ProtoSize::add_string_field(total_size, {field_id_size}, {name}, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 8  # field ID + 8 bytes typical bytes |         return self.calculate_field_id_size() + 8  # field ID + 8 bytes typical bytes | ||||||
| @@ -560,9 +576,7 @@ class UInt32Type(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_simple_size_calculation(name, force, "add_uint32_field") | ||||||
|         o = f"ProtoSize::add_uint32_field(total_size, {field_id_size}, {name}, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 3  # field ID + 3 bytes typical varint |         return self.calculate_field_id_size() + 3  # field ID + 3 bytes typical varint | ||||||
| @@ -590,9 +604,9 @@ class EnumType(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_simple_size_calculation( | ||||||
|         o = f"ProtoSize::add_enum_field(total_size, {field_id_size}, static_cast<uint32_t>({name}), {force_str(force)});" |             name, force, "add_enum_field", f"static_cast<uint32_t>({name})" | ||||||
|         return o |         ) | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 1  # field ID + 1 byte typical enum |         return self.calculate_field_id_size() + 1  # field ID + 1 byte typical enum | ||||||
| @@ -612,9 +626,7 @@ class SFixed32Type(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_fixed_size_calculation(name, force, 4, "!= 0") | ||||||
|         o = f"ProtoSize::add_fixed_field<4>(total_size, {field_id_size}, {name} != 0, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 4  # field ID + 4 bytes fixed |         return self.calculate_field_id_size() + 4  # field ID + 4 bytes fixed | ||||||
| @@ -634,9 +646,7 @@ class SFixed64Type(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_fixed_size_calculation(name, force, 8, "!= 0") | ||||||
|         o = f"ProtoSize::add_fixed_field<8>(total_size, {field_id_size}, {name} != 0, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 8  # field ID + 8 bytes fixed |         return self.calculate_field_id_size() + 8  # field ID + 8 bytes fixed | ||||||
| @@ -656,9 +666,7 @@ class SInt32Type(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_simple_size_calculation(name, force, "add_sint32_field") | ||||||
|         o = f"ProtoSize::add_sint32_field(total_size, {field_id_size}, {name}, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 3  # field ID + 3 bytes typical varint |         return self.calculate_field_id_size() + 3  # field ID + 3 bytes typical varint | ||||||
| @@ -678,9 +686,7 @@ class SInt64Type(TypeInfo): | |||||||
|         return o |         return o | ||||||
|  |  | ||||||
|     def get_size_calculation(self, name: str, force: bool = False) -> str: |     def get_size_calculation(self, name: str, force: bool = False) -> str: | ||||||
|         field_id_size = self.calculate_field_id_size() |         return self._get_simple_size_calculation(name, force, "add_sint64_field") | ||||||
|         o = f"ProtoSize::add_sint64_field(total_size, {field_id_size}, {name}, {force_str(force)});" |  | ||||||
|         return o |  | ||||||
|  |  | ||||||
|     def get_estimated_size(self) -> int: |     def get_estimated_size(self) -> int: | ||||||
|         return self.calculate_field_id_size() + 3  # field ID + 3 bytes typical varint |         return self.calculate_field_id_size() + 3  # field ID + 3 bytes typical varint | ||||||
| @@ -1712,7 +1718,6 @@ static const char *const TAG = "api.service"; | |||||||
|         exec_clang_format(root / "api_pb2_service.cpp") |         exec_clang_format(root / "api_pb2_service.cpp") | ||||||
|         exec_clang_format(root / "api_pb2.h") |         exec_clang_format(root / "api_pb2.h") | ||||||
|         exec_clang_format(root / "api_pb2.cpp") |         exec_clang_format(root / "api_pb2.cpp") | ||||||
|         exec_clang_format(root / "api_pb2_dump.h") |  | ||||||
|         exec_clang_format(root / "api_pb2_dump.cpp") |         exec_clang_format(root / "api_pb2_dump.cpp") | ||||||
|     except ImportError: |     except ImportError: | ||||||
|         pass |         pass | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user