[api] Share the fixed32 emission between float and fixed32 fields

One helper next to the other precomputed tag paths decides how a
single byte tag fixed32 field is written; the float and fixed32 types
only differ in the value expression. Drop the non forced std::string
encode_string overload, which the generator never emits, and build the
generator tests from one block of field type constants.
This commit is contained in:
J. Nick Koston
2026-09-07 10:33:21 +02:00
parent b77e2441d4
commit 490aca17e6
4 changed files with 47 additions and 43 deletions
@@ -45,7 +45,14 @@ UINT64 = descriptor_pb2.FieldDescriptorProto.TYPE_UINT64
INT64 = descriptor_pb2.FieldDescriptorProto.TYPE_INT64
SINT64 = descriptor_pb2.FieldDescriptorProto.TYPE_SINT64
UINT32 = descriptor_pb2.FieldDescriptorProto.TYPE_UINT32
INT32 = descriptor_pb2.FieldDescriptorProto.TYPE_INT32
SINT32 = descriptor_pb2.FieldDescriptorProto.TYPE_SINT32
FIXED64 = descriptor_pb2.FieldDescriptorProto.TYPE_FIXED64
FIXED32 = descriptor_pb2.FieldDescriptorProto.TYPE_FIXED32
FLOAT = descriptor_pb2.FieldDescriptorProto.TYPE_FLOAT
BOOL = descriptor_pb2.FieldDescriptorProto.TYPE_BOOL
STRING = descriptor_pb2.FieldDescriptorProto.TYPE_STRING
BYTES = descriptor_pb2.FieldDescriptorProto.TYPE_BYTES
def test_no_varint64_fields() -> None:
@@ -127,16 +134,16 @@ def _encode_field(
SCALAR_TYPES = [
descriptor_pb2.FieldDescriptorProto.TYPE_BOOL,
descriptor_pb2.FieldDescriptorProto.TYPE_UINT32,
descriptor_pb2.FieldDescriptorProto.TYPE_INT32,
descriptor_pb2.FieldDescriptorProto.TYPE_UINT64,
descriptor_pb2.FieldDescriptorProto.TYPE_INT64,
descriptor_pb2.FieldDescriptorProto.TYPE_SINT32,
descriptor_pb2.FieldDescriptorProto.TYPE_FLOAT,
descriptor_pb2.FieldDescriptorProto.TYPE_FIXED32,
descriptor_pb2.FieldDescriptorProto.TYPE_STRING,
descriptor_pb2.FieldDescriptorProto.TYPE_BYTES,
BOOL,
UINT32,
INT32,
UINT64,
INT64,
SINT32,
FLOAT,
FIXED32,
STRING,
BYTES,
]
@@ -165,10 +172,6 @@ def test_forced_fields_use_the_force_overload_or_raw_writes(field_type: int) ->
), content
FLOAT = descriptor_pb2.FieldDescriptorProto.TYPE_FLOAT
FIXED32 = descriptor_pb2.FieldDescriptorProto.TYPE_FIXED32
@pytest.mark.parametrize("field_type", [FLOAT, FIXED32])
def test_single_byte_tag_fixed32_shares_the_outlined_writer(field_type: int) -> None:
unconditional = _encode_field(field_type, force=True)