mirror of
https://github.com/esphome/esphome.git
synced 2026-09-22 12:38:40 +00:00
[api] Emit raw tag+value writes for force=true fixed32 fields
Instead of ALWAYS_INLINE on encode_field_raw (which bloated all callers), have the code generator precompute the tag byte and emit write_raw_byte(tag) + write_fixed32_raw(value) directly. This gives the same tight codegen (single byte store + memcpy) for key fields without inflating encode_bool/encode_uint32/etc. +108 bytes flash vs baseline, -48 bytes vs the ALWAYS_INLINE approach.
This commit is contained in:
@@ -556,6 +556,19 @@ class Fixed32Type(TypeInfo):
|
||||
o += "out.append(buffer);"
|
||||
return o
|
||||
|
||||
@property
|
||||
def encode_content(self) -> str:
|
||||
tag = (self.number << 3) | (self.wire_type & 0b111)
|
||||
if self.force and tag < 128:
|
||||
# Emit raw byte writes: precomputed tag + direct memcpy
|
||||
return (
|
||||
f"buffer.write_raw_byte({tag});\n"
|
||||
f"buffer.write_fixed32_raw(this->{self.field_name});"
|
||||
)
|
||||
if self.force:
|
||||
return f"buffer.{self.encode_func}({self.number}, this->{self.field_name}, true);"
|
||||
return f"buffer.{self.encode_func}({self.number}, this->{self.field_name});"
|
||||
|
||||
def get_size_calculation(self, name: str, force: bool = False) -> str:
|
||||
field_id_size = self.calculate_field_id_size()
|
||||
if force:
|
||||
|
||||
Reference in New Issue
Block a user