/// <summary> /// Parses an XML element and adds the field that it represents to a /// structure layout. /// </summary> /// <param name="layout">The layout to add the parsed field to.</param> /// <param name="element">The element to parse.</param> private static void HandleElement(StructureLayout layout, XElement element) { // Every structure field at least has a name and an offset string name = GetStringAttribute(element, "name"); int offset = GetNumericAttribute(element, "offset"); if (IsArrayElement(element)) { HandleArrayElement(layout, element, name, offset); } else { HandleBasicElement(layout, element, name, offset); } }
private StructureValueCollection _collection; // The values that are being written public static void WriteStructure(StructureValueCollection values, StructureLayout layout, IWriter writer) { StructureWriter structWriter = new StructureWriter(values, layout, writer); layout.Accept(structWriter); }
public void VisitArrayField(string name, int offset, int count, int entrySize, StructureLayout entryLayout) { StructureValueCollection[] arrayValue = _collection.GetArray(name); for (int i = 0; i < count; i++) { _writer.SeekTo(_baseOffset + offset + i * entrySize); WriteStructure(arrayValue[i], entryLayout, _writer); } }
/// <summary> /// Reads an array of values from the stream and adds it to the value /// collection which is currently being built. /// </summary> /// <param name="name">The name to store the array under.</param> /// <param name="offset">The array's offset (in bytes) from the beginning of the structure.</param> /// <param name="count">The number of elements to read into the array.</param> /// <param name="entrySize">The size (in bytes) of each element in the array.</param> /// <param name="entryLayout">The layout to follow for each entry in the array.</param> public void VisitArrayField(string name, int offset, int count, int entrySize, StructureLayout entryLayout) { StructureValueCollection[] arrayValue = new StructureValueCollection[count]; for (int i = 0; i < count; i++) { _reader.SeekTo(_baseOffset + offset + i * entrySize); arrayValue[i] = ReadStructure(_reader, entryLayout); } _collection.SetArray(name, arrayValue); }
/// <summary> /// Parses an XML element representing a basic structure field and adds /// the field information to a structure layout. /// </summary> /// <param name="layout">The structure layout to add the field's information to.</param> /// <param name="element">The XML element to parse.</param> /// <param name="name">The name of the field to add.</param> /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param> private static void HandleBasicElement(StructureLayout layout, XElement element, string name, int offset) { StructureValueType type = IdentifyValueType(element.Name.LocalName); layout.AddBasicField(name, type, offset); }
/// <summary> /// Adds an array field to the structure layout. /// </summary> /// <param name="name">The name of the array.</param> /// <param name="offset">The offset (in bytes) of the array from the beginning of the structure.</param> /// <param name="count">The number of entries in the array.</param> /// <param name="entrySize">The size of each entry in the array.</param> /// <param name="entryLayout">The layout of each entry in the array.</param> public void AddArrayField(string name, int offset, int count, int entrySize, StructureLayout entryLayout) { _fields.Add(new ArrayField(name, offset, count, entrySize, entryLayout)); }