This commit is contained in:
J. Nick Koston 2025-07-20 20:43:50 -10:00
parent c8140e966a
commit 756fc89eab
No known key found for this signature in database
2 changed files with 19 additions and 32 deletions

View File

@ -2283,9 +2283,9 @@ class VoiceAssistantAudio : public ProtoDecodableMessage {
#ifdef HAS_PROTO_MESSAGE_DUMP #ifdef HAS_PROTO_MESSAGE_DUMP
const char *message_name() const override { return "voice_assistant_audio"; } const char *message_name() const override { return "voice_assistant_audio"; }
#endif #endif
std::string data{};
const uint8_t *data_ptr_{nullptr}; const uint8_t *data_ptr_{nullptr};
size_t data_len_{0}; size_t data_len_{0};
std::string data{};
void set_data(const uint8_t *data, size_t len) { void set_data(const uint8_t *data, size_t len) {
this->data_ptr_ = data; this->data_ptr_ = data;
this->data_len_ = len; this->data_len_ = len;

View File

@ -113,8 +113,15 @@ def force_str(force: bool) -> str:
class TypeInfo(ABC): class TypeInfo(ABC):
"""Base class for all type information.""" """Base class for all type information."""
def __init__(self, field: descriptor.FieldDescriptorProto) -> None: def __init__(
self,
field: descriptor.FieldDescriptorProto,
needs_decode: bool = True,
needs_encode: bool = True,
) -> None:
self._field = field self._field = field
self._needs_decode = needs_decode
self._needs_encode = needs_encode
@property @property
def default_value(self) -> str: def default_value(self) -> str:
@ -598,49 +605,29 @@ class BytesType(TypeInfo):
reference_type = "std::string &" reference_type = "std::string &"
const_reference_type = "const std::string &" const_reference_type = "const std::string &"
encode_func = "encode_bytes" encode_func = "encode_bytes"
decode_length = "value.as_string()"
wire_type = WireType.LENGTH_DELIMITED # Uses wire type 2 wire_type = WireType.LENGTH_DELIMITED # Uses wire type 2
def __init__(
self,
field: descriptor.FieldDescriptorProto,
needs_decode: bool = True,
needs_encode: bool = True,
) -> None:
super().__init__(field)
self.needs_decode = needs_decode
self.needs_encode = needs_encode
# Only set decode_length if we need decoding
if needs_decode:
self.decode_length = "value.as_string()"
@property @property
def public_content(self) -> list[str]: def public_content(self) -> list[str]:
content = [] content: list[str] = []
# Add pointer/length fields if message needs encoding
if self.needs_encode:
content.extend(
[
f"const uint8_t* {self.field_name}_ptr_{{nullptr}};",
f"size_t {self.field_name}_len_{{0}};",
]
)
# Add std::string storage if message needs decoding # Add std::string storage if message needs decoding
if self.needs_decode: if self._needs_decode:
content.append(f"std::string {self.field_name}{{}};") content.append(f"std::string {self.field_name}{{}};")
# Add setter method if message needs encoding if self._needs_encode:
if self.needs_encode:
content.extend( content.extend(
[ [
# Add pointer/length fields if message needs encoding
f"const uint8_t* {self.field_name}_ptr_{{nullptr}};",
f"size_t {self.field_name}_len_{{0}};",
# Add setter method if message needs encoding
f"void set_{self.field_name}(const uint8_t* data, size_t len) {{", f"void set_{self.field_name}(const uint8_t* data, size_t len) {{",
f" this->{self.field_name}_ptr_ = data;", f" this->{self.field_name}_ptr_ = data;",
f" this->{self.field_name}_len_ = len;", f" this->{self.field_name}_len_ = len;",
"}", "}",
] ]
) )
return content return content
@property @property
@ -652,11 +639,11 @@ class BytesType(TypeInfo):
str_dump = f"format_hex_pretty(reinterpret_cast<const uint8_t*>(this->{self.field_name}.data()), this->{self.field_name}.size())" 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 # For SOURCE_CLIENT only, always use std::string
if not self.needs_encode: if not self._needs_encode:
return f"out.append({str_dump});" return f"out.append({str_dump});"
# For SOURCE_SERVER, always use pointer/length # For SOURCE_SERVER, always use pointer/length
if not self.needs_decode: if not self._needs_decode:
return f"out.append({ptr_dump});" return f"out.append({ptr_dump});"
# For SOURCE_BOTH, check if pointer is set (sending) or use string (received) # For SOURCE_BOTH, check if pointer is set (sending) or use string (received)