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

Function gen_write_data

rust/fory-derive/src/object/derive_enum.rs:591–625  ·  view source on GitHub ↗
(data_enum: &DataEnum)

Source from the content-addressed store, hash-verified

589}
590
591pub fn gen_write_data(data_enum: &DataEnum) -> TokenStream {
592 let default_variant_value = data_enum
593 .variants
594 .iter()
595 .position(is_default_value_variant)
596 .unwrap_or(0) as u32;
597
598 let xlang_variant_branches: Vec<TokenStream> =
599 xlang_variant_branches(data_enum, default_variant_value);
600 let rust_variant_branches: Vec<TokenStream> =
601 rust_variant_branches(data_enum, default_variant_value);
602 let rust_compatible_variant_branches: Vec<TokenStream> =
603 rust_compatible_variant_write_branches(data_enum, default_variant_value);
604
605 quote! {
606 if context.is_xlang() {
607 match self {
608 #(#xlang_variant_branches)*
609 }
610 Ok(())
611 } else {
612 if context.is_compatible() {
613 match self {
614 #(#rust_compatible_variant_branches)*
615 }
616 Ok(())
617 } else {
618 match self {
619 #(#rust_variant_branches)*
620 }
621 Ok(())
622 }
623 }
624 }
625}
626
627pub fn gen_write_type_info(data_enum: &DataEnum) -> TokenStream {
628 let is_union_compatible = is_union_compatible_enum(data_enum);

Callers

nothing calls this directly

Calls 4

xlang_variant_branchesFunction · 0.85
rust_variant_branchesFunction · 0.85
positionMethod · 0.80

Tested by

no test coverage detected