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

Function skip_enum_variant

rust/fory-core/src/serializer/skip.rs:850–888  ·  view source on GitHub ↗

Skip enum variant data in compatible mode based on variant type. # Arguments `context` - The read context `variant_type` - The variant type encoded in lower 2 bits: - 0b0 = Unit variant (no data to skip) - 0b1 = Unnamed variant (tuple data) - 0b10 = Named variant (struct-like data) `type_info` - Optional type info for named variants (must be provided for 0b10)

(
    context: &mut ReadContext,
    variant_type: u32,
    type_info: &Option<Rc<crate::TypeInfo>>,
)

Source from the content-addressed store, hash-verified

848/// - 0b10 = Named variant (struct-like data)
849/// * `type_info` - Optional type info for named variants (must be provided for 0b10)
850pub fn skip_enum_variant(
851 context: &mut ReadContext,
852 variant_type: u32,
853 type_info: &Option<Rc<crate::TypeInfo>>,
854) -> Result<(), Error> {
855 match variant_type {
856 0b0 => {
857 // Unit variant, no data to skip
858 Ok(())
859 }
860 0b1 => {
861 // Unnamed variant, skip tuple data (which is serialized as a collection)
862 // Tuple uses collection format but doesn't write type info, so skip directly
863 let field_type = FieldType::new(types::LIST, false, vec![unknown_field_type()]);
864 skip_collection(context, &field_type)
865 }
866 0b10 => {
867 // Named variant, skip struct-like data using skip_struct
868 // For named variants, we need the type_info which should have been read already
869 if type_info.is_some() {
870 let type_id = type_info.as_ref().unwrap().get_type_id() as u32;
871 skip_struct(context, type_id, type_info)
872 } else {
873 // If no type_info provided, read it inline using streaming protocol
874 let type_info_rc = context.read_type_meta()?;
875 let type_id = type_info_rc.get_type_id() as u32;
876 let type_info_opt = Some(type_info_rc);
877 skip_struct(context, type_id, &type_info_opt)
878 }
879 }
880 _ => {
881 // Invalid variant type
882 Err(Error::type_error(format!(
883 "Invalid enum variant type: {}",
884 variant_type
885 )))
886 }
887 }
888}

Callers

nothing calls this directly

Calls 6

skip_collectionFunction · 0.85
SomeFunction · 0.85
skip_structFunction · 0.70
get_type_idMethod · 0.45
unwrapMethod · 0.45
read_type_metaMethod · 0.45

Tested by

no test coverage detected