Beispiel #1
0
        private static RecordingAttribute getAttribute(StringBuilder name, StreamBufferAttrDataType attributeType, byte[] attributeValue)
        {
            string attributeName = name.ToString().TrimEnd('\0');
            string type          = attributeType.ToString();

            switch (attributeType)
            {
            case StreamBufferAttrDataType.Binary:
                RecordingAttribute binaryAttribute = new RecordingAttribute(attributeName, type, attributeValue);
                return(binaryAttribute);

            case StreamBufferAttrDataType.Bool:
                RecordingAttribute boolAttribute = new RecordingAttribute(attributeName, type, attributeValue[0] == 0);
                return(boolAttribute);

            case StreamBufferAttrDataType.DWord:
                int intValue = attributeValue[0] << 24 | attributeValue[1] << 16 | attributeValue[2] << 8 | attributeValue[3];
                RecordingAttribute intAttribute = new RecordingAttribute(attributeName, type, intValue);
                return(intAttribute);

            case StreamBufferAttrDataType.Guid:
                RecordingAttribute guidAttribute = new RecordingAttribute(attributeName, type, new Guid(attributeValue));
                return(guidAttribute);

            case StreamBufferAttrDataType.QWord:
                long longValue = attributeValue[0] << 56 | attributeValue[1] << 48 | attributeValue[2] << 40
                                 | attributeValue[3] << 32 | attributeValue[4] << 24 | attributeValue[5] << 16
                                 | attributeValue[6] << 8 | attributeValue[7];
                RecordingAttribute longAttribute = new RecordingAttribute(attributeName, type, longValue);
                return(longAttribute);

            case StreamBufferAttrDataType.String:
                Encoding sourceEncoding = Encoding.GetEncoding("utf-16");
                if (sourceEncoding == null)
                {
                    return(null);
                }
                string             encodedString   = sourceEncoding.GetString(attributeValue, 0, attributeValue.Length);
                RecordingAttribute stringAttribute = new RecordingAttribute(attributeName, type, encodedString);
                return(stringAttribute);

            case StreamBufferAttrDataType.Word:
                int shortValue = attributeValue[0] << 8 | attributeValue[1];
                RecordingAttribute shortAttribute = new RecordingAttribute(attributeName, type, shortValue);
                return(shortAttribute);

            default:
                return(null);
            }
        }
        private static RecordingAttribute getAttribute(StringBuilder name, StreamBufferAttrDataType attributeType, byte[] attributeValue)
        {
            string attributeName = name.ToString().TrimEnd('\0');
            string type = attributeType.ToString();

            switch (attributeType)
            {
                case StreamBufferAttrDataType.Binary:
                    RecordingAttribute binaryAttribute = new RecordingAttribute(attributeName, type, attributeValue);
                    return (binaryAttribute);
                case StreamBufferAttrDataType.Bool:
                    RecordingAttribute boolAttribute = new RecordingAttribute(attributeName, type, attributeValue[0] == 0);
                    return (boolAttribute);
                case StreamBufferAttrDataType.DWord:
                    int intValue = attributeValue[0] << 24 | attributeValue[1] << 16 | attributeValue[2] << 8 | attributeValue[3];
                    RecordingAttribute intAttribute = new RecordingAttribute(attributeName, type, intValue);
                    return (intAttribute);
                case StreamBufferAttrDataType.Guid:
                    RecordingAttribute guidAttribute = new RecordingAttribute(attributeName, type, new Guid(attributeValue));
                    return (guidAttribute);
                case StreamBufferAttrDataType.QWord:
                    long longValue = attributeValue[0] << 56 | attributeValue[1] << 48 | attributeValue[2] << 40
                        | attributeValue[3] << 32 | attributeValue[4] << 24 | attributeValue[5] << 16
                        | attributeValue[6] << 8 | attributeValue[7];
                    RecordingAttribute longAttribute = new RecordingAttribute(attributeName, type, longValue);
                    return (longAttribute);
                case StreamBufferAttrDataType.String:
                    Encoding sourceEncoding = Encoding.GetEncoding("utf-16");
                    if (sourceEncoding == null)
                        return (null);
                    string encodedString = sourceEncoding.GetString(attributeValue,  0, attributeValue.Length);
                    RecordingAttribute stringAttribute = new RecordingAttribute(attributeName, type, encodedString);
                    return (stringAttribute);
                case StreamBufferAttrDataType.Word:
                    int shortValue = attributeValue[0] << 8 | attributeValue[1];
                    RecordingAttribute shortAttribute = new RecordingAttribute(attributeName, type, shortValue);
                    return (shortAttribute);
                default:
                    return (null);
            }
        }