Skip to content

Commit aabd70e

Browse files
rustyconoverclaude
andcommitted
cpp_records: no enum wire aliases; enums decode by canonical name only
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent ef53d91 commit aabd70e

1 file changed

Lines changed: 0 additions & 27 deletions

File tree

‎vgi/codegen/cpp_records.py‎

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,6 @@
9191
}
9292

9393

94-
#: Extra wire spellings the C++ client accepts for an enum (C++ enum name -> {spelling: member
95-
#: NAME}). Only spellings peers really send, which the hand-written client always accepted:
96-
#: vgi-go, vgi-rust and vgi-java send ``function_type`` / ``macro_type`` in lower case, and
97-
#: ``table_in_out`` is the legacy name of TABLE. Encoding always writes the canonical name.
98-
ENUM_WIRE_ALIASES: dict[str, dict[str, str]] = {
99-
"FunctionType": {
100-
"scalar": "SCALAR",
101-
"table": "TABLE",
102-
"table_in_out": "TABLE",
103-
"table_buffering": "TABLE_BUFFERING",
104-
"aggregate": "AGGREGATE",
105-
},
106-
# vgi-go, vgi-rust and vgi-java send macro_type in lower case too.
107-
"MacroType": {"scalar": "SCALAR", "table": "TABLE"},
108-
}
109-
110-
11194
def cpp_name(py_name: str) -> str:
11295
"""The C++ type name for a protocol type's Python name."""
11396
return CPP_NAMES.get(py_name) or cs.csharp_name(py_name)
@@ -504,16 +487,6 @@ def _render_source(model: _Model, namespace: list[str]) -> str:
504487
out.write(f"std::optional<{e.name}> {e.name}FromWire(const std::string &wire) {{\n")
505488
out.write(f"\tfor (int16_t i = 0; i < k{e.name}Count; i++) {{\n")
506489
out.write(f"\t\tif (wire == k{e.name}Wire[i]) {{\n\t\t\treturn static_cast<{e.name}>(i);\n\t\t}}\n\t}}\n")
507-
aliases = ENUM_WIRE_ALIASES.get(e.name, {})
508-
if aliases:
509-
member_ident = {m.wire_name: m.ident for m in e.members}
510-
out.write(
511-
"\t// Accepted spellings beyond the canonical names (vgi.codegen.cpp_records.ENUM_WIRE_ALIASES).\n"
512-
)
513-
for alias, member in sorted(aliases.items()):
514-
if member not in member_ident:
515-
raise GeneratorError(f"{e.name}: alias {alias!r} names unknown member {member!r}")
516-
out.write(f'\tif (wire == "{alias}") {{\n\t\treturn {e.name}::{member_ident[member]};\n\t}}\n')
517490
out.write("\treturn std::nullopt;\n}\n\n")
518491
out.write(f"void ReadValue(const arrow::Array &array, int64_t i, {e.name} &out, const wire::Ctx &ctx) {{\n")
519492
out.write("\tstd::string s;\n\twire::ReadValue(array, i, s, ctx);\n")

0 commit comments

Comments
 (0)