/// Serializes to Rust type, returns None if not implemented
Serializes to Rust type, returns None if not implemented
Serializes to Rust type returns None if not implemented
fn from_field(field: FieldTypeSerialization, protocol_version: u32) -> Option<Self> {
        use FieldType::*;
        use FieldTypeSerialization::*;
        let ty = match field {
            GenerateVariableTypes(field, _) => &field.r#type,
            GenerateVariableTypesCompound(ty, _, _) | PlainOnly(ty) => ty,
        };
        Some(match ty {
            Varint => "VarIntField".into(),
            U16 => "UShortField".into(),
            U8 => "UByteField".into(),
            I64 => "LongField".into(),
            I32 => "IntField".into(),
            I8 => "ByteField".into(),
            I16 => "ShortField".into(),
            F32 => "FloatField".into(),
            F64 => "DoubleField".into(),
            Bool => "BoolField".into(),
            String => "StringField".into(),
            Buffer { count_ty } if matches!(**count_ty, FieldType::Varint) => {
                "VarIntThenByteArrayField".into()
            }
            Array { count, elem_ty } => {
                let elem_ty = Self::from_field(field.nest(elem_ty), protocol_version)?;
                match count {
                    ArrayCount::Constant(n) => format!("[{}; {}]", elem_ty.ident(), n),
                    ArrayCount::Prefixed(n) if matches!(**n, FieldType::Varint) => {
                        format!("PrefixedArrayField<VarIntField, {}>", elem_ty.ident())
                    }
                    _ => return None,
                }
                .into()
            }
            Void => "()".into(), // TODO voidfield
            // Uuid => {}
            // EntityMetadata => {}
            Position => format!("PositionField<{}>", protocol_version).into(),
            RestOfBuffer => "RestOfPacketByteArrayField".into(),
            Nbt => "NbtField".into(),
            // OptionalNbt => {}
            Switch(switch) => {
                if let FieldTypeSerialization::GenerateVariableTypes(field, packet) = field {
                    RustType::Generated(VariableType::from_switch(
                        switch,
                        field,
                        packet,
                        protocol_version,
                    ))
                } else {
                    return None;
                }
            }
            // Container(fields) => {}
            // Slot => {}
            // ParticleData => {}
            // Option(_) => {}
            // Bitfield => {}
            // TopBitSetTerminatedArray => {}
            _ => return None,
        })
    }
fn from_field ( field : FieldTypeSerialization , protocol_version : u32 ) -> Option < Self > { use FieldType :: * ; use FieldTypeSerialization :: * ; let ty = match field { GenerateVariableTypes ( field , _ ) => & field . r#type , GenerateVariableTypesCompound ( ty , _ , _ ) | PlainOnly ( ty ) => ty , } ; Some ( match ty { Varint => " " . into ( ) , U16 => " " . into ( ) , U8 => " " . into ( ) , I64 => " " . into ( ) , I32 => " " . into ( ) , I8 => " " . into ( ) , I16 => " " . into ( ) , F32 => " " . into ( ) , F64 => " " . into ( ) , Bool => " " . into ( ) , String => " " . into ( ) , Buffer { count_ty } if matches ! ( count_ty FieldType Varint ) => { " " . into ( ) } Array { count , elem_ty } => { let elem_ty = Self :: from_field ( field . nest ( elem_ty ) , protocol_version ) ? ; match count { ArrayCount :: Constant ( n ) => format ! ( " " elem_ty ident ( ) n ) , ArrayCount :: Prefixed ( n ) if matches ! ( n FieldType Varint ) => { format ! ( " " elem_ty ident ( ) ) } _ => return None , } . into ( ) } Void => " " . into ( ) , // TODO voidfield // Uuid => {} // EntityMetadata => {} Position => format ! ( " " protocol_version ) . into ( ) , RestOfBuffer => " " . into ( ) , Nbt => " " . into ( ) , // OptionalNbt => {} Switch ( switch ) => { if let FieldTypeSerialization :: GenerateVariableTypes ( field , packet ) = field { RustType :: Generated ( VariableType :: from_switch ( switch , field , packet , protocol_version , ) ) } else { return None ; } } // Container(fields) => {} // Slot => {} // ParticleData => {} // Option(_) => {} // Bitfield => {} // TopBitSetTerminatedArray => {} _ => return None , } ) }
Serializes to Rust type, returns None if not implemented
Serializes to Rust type returns None if not implemented
field
FieldTypeSerialization
protocol_version
u32