/// <summary> /// Reads the contents of the <see cref="EhfaStructure" /> from the specified stream. /// </summary> /// <param name="stream">The stream.</param> /// <exception cref="System.ArgumentNullException">The stream is null.</exception> /// <exception cref="System.ArgumentException">The stream is invalid.</exception> public virtual void Read(Stream stream) { if (stream == null) { throw new ArgumentNullException(nameof(stream), "The stream is null."); } try { foreach (DictionaryEntry structureItem in _type.Items) { IEhfaObject value = null; IEhfaObjectType item = (IEhfaObjectType)structureItem.Value; if (item is EhfaPrimitiveType) { value = new EhfaObject(item as EhfaPrimitiveType); value.Read(stream); _objects.Add((String)structureItem.Key, value); } else if (item is EhfaStructureType) { if (item.DataPlacement == DataPlacement.Internal) { value = new EhfaStructure(item as EhfaStructureType); value.Read(stream); _objects.Add((String)structureItem.Key, value); } if (item.DataPlacement != DataPlacement.Internal) { Byte[] temp = new Byte[4]; stream.Read(temp, 0, 4); Int32 objectRepeatCount = (Int32)EndianBitConverter.ToUInt32(temp, ByteOrder.LittleEndian); stream.Read(temp, 0, 4); UInt32 pointer = EndianBitConverter.ToUInt32(temp, ByteOrder.LittleEndian); _objectLocations[(String)structureItem.Key] = new List <IEhfaObject>(); if (objectRepeatCount == 0) { continue; } while (objectRepeatCount-- > 0) { value = new EhfaStructure(item as EhfaStructureType); value.Read(stream); _objectLocations[(String)structureItem.Key].Add(value as EhfaStructure); } } } } } catch (Exception ex) { throw new ArgumentException("The stream is invalid.", nameof(stream), ex); } }
/// <summary> /// Parses the item definitions. /// </summary> /// <param name="definitions">The item definitions.</param> private void ParseItemDefinitions(String definitions) { Items = new OrderedDictionary(); Int32 index = 0; while (index < definitions.Length) { Int32 itemNumber = GetItemNumber(definitions, ref index); DataPlacement placement = GetDataPlacement(definitions, ref index); ItemType itemType = GetItemType(definitions, ref index); List <String> enumItems = null; IEhfaObjectType ehfaObjectType = null; if (itemType == ItemType.Enum) { enumItems = GetEnumItems(definitions, ref index); } if (itemType == ItemType.PreviouslyDefined) { ehfaObjectType = GetPreviouslyDefinedObjectType(definitions, placement, ref index); } if (itemType == ItemType.FollowedDefined) { ehfaObjectType = GetFollowingDefinedObjectType(definitions, ref index); } String itemName = GetItemName(definitions, ref index); if (ehfaObjectType == null) { if (itemType == ItemType.Enum) { ehfaObjectType = new EhfaPrimitiveType(itemName, itemNumber, placement, enumItems); } else { ehfaObjectType = new EhfaPrimitiveType(itemName, itemNumber, itemType, placement); } } Items.Add(itemName, ehfaObjectType); } }