1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-13 08:42:18 +01:00

Fix bytes field encoding in protobuf code generator

This commit is contained in:
J. Nick Koston
2025-07-01 20:26:34 -05:00
parent 04a46de237
commit 6e42d009fb
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("\'").append({name}).append("\'");'
return o