diff --git a/script/api_protobuf/api_protobuf.py b/script/api_protobuf/api_protobuf.py index 4ea09f0687d..fa20a931c32 100755 --- a/script/api_protobuf/api_protobuf.py +++ b/script/api_protobuf/api_protobuf.py @@ -244,10 +244,10 @@ class TypeInfo(ABC): "encode_bool": "buffer.write_raw_byte({value} ? 0x01 : 0x00);", } - # When max_value < 128, the varint is always 1 byte — use encode_small_varint + # When max_value < 128 and forced, the varint is always 1 byte — write tag + value directly RAW_ENCODE_SMALL_MAP: dict[str, str] = { - "encode_uint32": "buffer.encode_small_varint({tag}, static_cast({value}));", - "encode_uint64": "buffer.encode_small_varint({tag}, static_cast({value}));", + "encode_uint32": "buffer.write_raw_byte(static_cast({value}));", + "encode_uint64": "buffer.write_raw_byte(static_cast({value}));", } def _encode_with_precomputed_tag(self, value_expr: str) -> str | None: @@ -270,12 +270,6 @@ class TypeInfo(ABC): raw_expr = self.RAW_ENCODE_MAP.get(self.encode_func) if raw_expr is None: return None - if ( - max_val is not None - and max_val < 128 - and self.encode_func in self.RAW_ENCODE_SMALL_MAP - ): - return raw_expr.format(tag=tag, value=value_expr) return f"buffer.write_raw_byte({tag});\n{raw_expr.format(value=value_expr)}" def _encode_bytes_with_precomputed_tag(