/// <summary>Initializes the metadata item.</summary> /// <param name="name">The name of the attribute.</param> /// <param name="value">The value of the attribute.</param> /// <param name="type">The type of the attribute value.</param> public MetadataItem(string name, object value, StreamBufferAttrDataType type) { Name = name; Value = value; Type = type; }
/// <summary>Initializes the metadata item.</summary> /// <param name="name">The name of the attribute.</param> /// <param name="value">The value of the attribute.</param> /// <param name="type">The type of the attribute value.</param> public MetadataItem(string name, object value, StreamBufferAttrDataType type) { Name = name; Value = value; Type = type; }
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); } }
/// <summary>Gets the value of the specified attribute.</summary> /// <param name="itemType">The type of the attribute.</param> /// <param name="valueData">The byte array to be parsed.</param> protected static object ParseAttributeValue(StreamBufferAttrDataType itemType, byte[] valueData) { if (!Enum.IsDefined(typeof(StreamBufferAttrDataType), itemType)) throw new ArgumentOutOfRangeException("itemType"); if (valueData == null) throw new ArgumentNullException("valueData"); // Convert the attribute value to a byte array based on the item type. switch (itemType) { case StreamBufferAttrDataType.String: StringBuilder sb = new StringBuilder(valueData.Length); for (int i = 0; i < valueData.Length - 2; i += 2) { sb.Append(Convert.ToString(BitConverter.ToChar(valueData, i), System.Globalization.CultureInfo.InvariantCulture)); } string result = sb.ToString(); if (result.EndsWith("\\0")) result = result.Substring(0, result.Length - 2); return result; case StreamBufferAttrDataType.Bool: return BitConverter.ToBoolean(valueData, 0); case StreamBufferAttrDataType.DWord: return BitConverter.ToInt32(valueData, 0); case StreamBufferAttrDataType.QWord: return BitConverter.ToInt64(valueData, 0); case StreamBufferAttrDataType.Word: return BitConverter.ToInt16(valueData, 0); case StreamBufferAttrDataType.Guid: return new Guid(valueData); case StreamBufferAttrDataType.Binary: return valueData; default: throw new ArgumentOutOfRangeException("itemType"); } }