This commit is contained in:
J. Nick Koston 2025-07-20 20:08:57 -10:00
parent b24ff7236e
commit 8c11241af0
No known key found for this signature in database

View File

@ -657,20 +657,23 @@ class BytesType(TypeInfo):
return f"buffer.encode_bytes({self.number}, this->{self.field_name}_ptr_, this->{self.field_name}_len_);"
def dump(self, name: str) -> str:
ptr_dump = f"format_hex_pretty(this->{self.field_name}_ptr_, this->{self.field_name}_len_)"
str_dump = f"format_hex_pretty(reinterpret_cast<const uint8_t*>(this->{self.field_name}.data()), this->{self.field_name}.size())"
# For SOURCE_CLIENT only, always use std::string
if not self.needs_encode:
return f"out.append(format_hex_pretty(reinterpret_cast<const uint8_t*>(this->{self.field_name}.data()), this->{self.field_name}.size()));"
return f"out.append({str_dump});"
# For SOURCE_SERVER, always use pointer/length
if not self.needs_decode:
return f"out.append(format_hex_pretty(this->{self.field_name}_ptr_, this->{self.field_name}_len_));"
return f"out.append({ptr_dump});"
# For SOURCE_BOTH, check if pointer is set (sending) or use string (received)
return (
f"if (this->{self.field_name}_ptr_ != nullptr) {{\n"
f" out.append(format_hex_pretty(this->{self.field_name}_ptr_, this->{self.field_name}_len_));\n"
f" out.append({ptr_dump});\n"
f" }} else {{\n"
f" out.append(format_hex_pretty(reinterpret_cast<const uint8_t*>(this->{self.field_name}.data()), this->{self.field_name}.size()));\n"
f" out.append({str_dump});\n"
f" }}"
)