MCPcopy Create free account
hub / github.com/apache/fory / get_union_field_meta

Method get_union_field_meta

compiler/fory_compiler/generators/cpp.py:1588–1617  ·  view source on GitHub ↗

Build FieldMeta expression for a union case.

(self, field: Field)

Source from the content-addressed store, hash-verified

1586 return meta
1587
1588 def get_union_field_meta(self, field: Field) -> str:
1589 """Build FieldMeta expression for a union case."""
1590 meta = f"fory::F({field.number})"
1591 is_any = (
1592 isinstance(field.field_type, PrimitiveType)
1593 and field.field_type.kind == PrimitiveKind.ANY
1594 )
1595 if field.optional or is_any:
1596 meta += ".nullable()"
1597 if field.ref:
1598 meta += ".ref()"
1599 spec = self.get_field_type_spec(field)
1600 if spec:
1601 if field.optional or field.ref:
1602 meta += f".inner({spec})"
1603 elif spec.startswith("fory::T::list("):
1604 meta += f".list({spec[len('fory::T::list(') : -1]})"
1605 elif spec.startswith("fory::T::array("):
1606 meta += f".array({spec[len('fory::T::array(') : -1]})"
1607 elif spec.startswith("fory::T::set("):
1608 meta += f".set({spec[len('fory::T::set(') : -1]})"
1609 elif spec.startswith("fory::T::map("):
1610 meta += f".map({spec[len('fory::T::map(') : -1]})"
1611 elif spec.endswith(".fixed()"):
1612 meta += ".fixed()"
1613 elif spec.endswith(".varint()"):
1614 meta += ".varint()"
1615 elif spec.endswith(".tagged()"):
1616 meta += ".tagged()"
1617 return meta
1618
1619 def get_field_type_spec(self, field: Field) -> str:
1620 """Return the T-node spec for a field when generated metadata needs it."""

Callers 1

generate_union_macrosMethod · 0.95

Calls 1

get_field_type_specMethod · 0.95

Tested by

no test coverage detected