1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-01 10:52:19 +01:00

Use encode_bytes() for protobuf bytes fields (#9289)

This commit is contained in:
J. Nick Koston
2025-07-01 23:36:09 -05:00
committed by GitHub
parent fae96e279c
commit eba2c82fec
2 changed files with 18 additions and 12 deletions

View File

@@ -526,9 +526,13 @@ class BytesType(TypeInfo):
reference_type = "std::string &"
const_reference_type = "const std::string &"
decode_length = "value.as_string()"
encode_func = "encode_string"
encode_func = "encode_bytes"
wire_type = WireType.LENGTH_DELIMITED # Uses wire type 2
@property
def encode_content(self) -> str:
return f"buffer.encode_bytes({self.number}, reinterpret_cast<const uint8_t*>(this->{self.field_name}.data()), this->{self.field_name}.size());"
def dump(self, name: str) -> str:
o = f"out.append(format_hex_pretty({name}));"
return o