Use write_short_string for non-forced strings with max_data_length < 128

Add empty check wrapper for non-forced short strings instead of falling
through to the general encode_string path.
This commit is contained in:
J. Nick Koston
2026-04-06 08:43:24 -10:00
parent 33285dfe27
commit 4099064207
2 changed files with 77 additions and 38 deletions
+5 -2
View File
@@ -1088,10 +1088,13 @@ class PointerToStringBufferType(PointerToBufferTypeBase):
@property
def encode_content(self) -> str:
max_len = self.max_data_length
if max_len is not None and max_len < 128 and self.force:
if max_len is not None and max_len < 128:
tag = self.calculate_tag()
if tag < 128:
return f"ProtoEncode::write_short_string(pos PROTO_ENCODE_DEBUG_ARG, {tag}, this->{self.field_name});"
call = f"ProtoEncode::write_short_string(pos PROTO_ENCODE_DEBUG_ARG, {tag}, this->{self.field_name});"
if self.force:
return call
return f"if (!this->{self.field_name}.empty())\n {call}"
if result := self._encode_bytes_with_precomputed_tag(
f"this->{self.field_name}.c_str()",
f"this->{self.field_name}.size()",