def cast_field_value(self, protocol, field_name, field_value):
        """Casts the field value to its proper type according to the mapping"""
        if isinstance(field_value, list):
            return [self.cast_field_value(protocol, field_name, item) for item in field_value]
        if not isinstance(field_value, str):
            return field_value
        field_type = self.get_field_type(protocol, field_name)
        if field_type == str:
            return field_value
        if field_type == int and field_value.startswith("0x"):
            return int(field_value, 16)
        if field_type == bytes:
            try:
                return binascii.unhexlify(field_value.replace(":", ""))
            except binascii.Error:
                return field_value

        try:
            return field_type(field_value)
        except ValueError:
            return field_value
Casts the field value to its proper type according to the mapping
src/pyshark/ek_field_mapping.py