public static object ToValue(this ReadValueType valueType, byte[] data)
        {
            switch (valueType)
            {
            case ReadValueType.Word:
                return(BitConverter.ToUInt16(data, 0));

            case ReadValueType.DWord:
                return(BitConverter.ToUInt32(data, 0));

            case ReadValueType.QWord:
                return(BitConverter.ToUInt64(data, 0));

            case ReadValueType.SignedByte:
                return((data[0] & 0x7f) - (data[0] & 0x80));

            case ReadValueType.SignedWord:
                return(BitConverter.ToInt16(data, 0));

            case ReadValueType.SignedDWord:
                return(BitConverter.ToInt32(data, 0));

            case ReadValueType.SignedQWord:
                return(BitConverter.ToInt64(data, 0));

            case ReadValueType.Float:
                return(BitConverter.ToSingle(data, 0));

            case ReadValueType.Double:
                return(BitConverter.ToDouble(data, 0));

            case ReadValueType.ASCII:
                return(Encoding.ASCII.GetString(data).Replace("\0", "."));

            case ReadValueType.UnicodeLE:
                return(Encoding.Unicode.GetString(data).Replace("\0", "."));;

            case ReadValueType.UnicodeBE:
                return(Encoding.BigEndianUnicode.GetString(data).Replace("\0", "."));

            case ReadValueType.UTF8:
                return(Encoding.UTF8.GetString(data).Replace("\0", "."));

            default:
                return(data[0]);
            }
        }
Beispiel #2
0
        public static ulong ToValue(this ReadValueType valueType, byte[] data)
        {
            switch (valueType)
            {
            case ReadValueType.Word:
                return(BitConverter.ToUInt16(data, 0));

            case ReadValueType.DWord:
                return(BitConverter.ToUInt32(data, 0));

            case ReadValueType.QWord:
                return(BitConverter.ToUInt64(data, 0));

            default:
                return(data[0]);
            }
        }
 public static string GetReadValueTypeName(this ReadValueType valueType)
 {
     return(ValueTypeNames[(int)valueType]);
 }
 public static bool IsVariableSize(this ReadValueType valueType)
 {
     return(valueType > ReadValueType.Double);
 }