Implement UUID CRC32 and byte order compatibility

This commit is contained in:
2026-08-08 22:07:19 +00:00
parent e63f2c615a
commit 28a6f54f7e
15 changed files with 1309 additions and 202 deletions

View File

@@ -34,6 +34,25 @@ TARGETS = {
"LibreMetaverse.Voice.WebRTC": ROOT / "crates/libremetaverse-voice-webrtc/src/generated.rs",
}
# Types whose failure-only generated shells have been replaced by native Rust
# implementations. The generated module keeps catalog markers and re-exports
# the hand-written type so coverage remains deterministic.
NATIVE_TYPES = {
"T:LibreMetaverse.CRC32": "crate::crc32::CRC32",
"T:LibreMetaverse.UUID": "crate::uuid::UUID",
}
NATIVE_MEMBER_BODIES = {
"M:LibreMetaverse.Utils.ReadSingleLittleEndian(System.Byte[],System.Int32)":
"crate::byte_order::read_single_little_endian(src, pos)",
"M:LibreMetaverse.Utils.WriteSingleLittleEndian(System.Byte[],System.Int32,System.Single)":
"crate::byte_order::write_single_little_endian(dest, pos, value)",
"M:LibreMetaverse.Utils.ReadDoubleLittleEndian(System.Byte[],System.Int32)":
"crate::byte_order::read_double_little_endian(src, pos)",
"M:LibreMetaverse.Utils.WriteDoubleLittleEndian(System.Byte[],System.Int32,System.Double)":
"crate::byte_order::write_double_little_endian(dest, pos, value)",
}
MAIN_TARGET = ROOT / "crates/libremetaverse/src/generated.rs"
WIRE_NAMESPACES = (
"LibreMetaverse.Assets",
@@ -539,6 +558,8 @@ def render_enum(item: dict, rust_name: str) -> list[str]:
def render_body(signature: str, member_id: str, error_model: str, asyncness: str, trait: bool) -> str:
if trait:
signature = signature.removeprefix("pub ")
if member_id in NATIVE_MEMBER_BODIES:
return f" {signature} {{ {NATIVE_MEMBER_BODIES[member_id]} }}"
failure = (
f"libremetaverse_types::not_implemented({json.dumps(member_id)})"
if error_model.startswith("Result")
@@ -564,6 +585,11 @@ def rust_constant_value(item: dict) -> str:
def render_type(item: dict, type_row: dict, member_rows: dict[str, dict[str, str]], mapper: mapping.Mapper) -> str:
rust_name = type_name(type_row)
if native_path := NATIVE_TYPES.get(item["doc_id"]):
lines = [f"/// C# type: `{item['doc_id']}`."]
lines.extend(f"/// C# member: `{member['doc_id']}`." for member in item["members"])
lines.append(f"pub use {native_path} as {rust_name};")
return "\n".join(lines)
if item["kind"] == "enum":
return "\n".join(render_enum(item, rust_name))
names = generic_names(item)
@@ -803,7 +829,22 @@ def coverage_report(catalog: dict, coverage: dict[str, tuple[int, int, bool]]) -
got_types, got_members, complete = coverage[name]
if complete and (types, members) != (got_types, got_members):
raise ValueError(f"incomplete generated slice for {name}")
status = "callable failure-only shim" if complete else f"partial callable shim ({got_types:,} types / {got_members:,} members)"
native_type_ids = {
item["doc_id"] for item in assembly["types"] if item["doc_id"] in NATIVE_TYPES
}
native_member_ids = {
member["doc_id"]
for item in assembly["types"]
for member in item["members"]
if item["doc_id"] in native_type_ids or member["doc_id"] in NATIVE_MEMBER_BODIES
}
if native_type_ids or native_member_ids:
status = (
f"native implementation: {len(native_type_ids):,} types / "
f"{len(native_member_ids):,} members; remaining surface is callable failure-only shims"
)
else:
status = "callable failure-only shim" if complete else f"partial callable shim ({got_types:,} types / {got_members:,} members)"
total_types += got_types
total_members += got_members
else: