private IList ReadArray(BinaryDataReader reader, Type type, int length) { // Use a given instance as the root array if available. IList array; if (_instance == null) { array = InstantiateType <IList>(type); } else { array = (IList)_instance; _instance = null; } // Find the generic element type by looking at the indexer (this allows IList-inheriting classes to work). Type elementType = type.GetTypeInfo().GetElementType(); // Read the element types of the array. All elements must be of same type or serialization is impossible. byte[] nodeTypes = reader.ReadBytes(length); // Read the elements, which begin after a padding to the next 4 bytes. reader.Align(4); for (int i = 0; i < length; i++) { array.Add(ReadValue(reader, elementType, (ByamlNodeType)nodeTypes[i])); } return(array); }
// ---- CONSTRUCTORS & DESTRUCTOR ------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="StringGroup"/> class, reading data with the given parameters. /// </summary> /// <param name="reader">The <see cref="BinaryDataReader"/> to read the data from.</param> /// <param name="section">The <see cref="SectionBase"/> this group belongs to.</param> /// <param name="sectionLength">The size of the section data in bytes.</param> internal StringGroup(BinaryDataReader reader, SectionBase section, int sectionLength) : base(reader, section, sectionLength) { // Get the offsets and read the strings at them. int[] offsets = reader.ReadInt32s(section.ElementCount); long stringArrayOffset = reader.Position; for (int i = 0; i < offsets.Length; i++) { reader.Seek(stringArrayOffset + offsets[i], SeekOrigin.Begin); Add(reader.ReadString(BinaryStringFormat.ZeroTerminated)); } reader.Align(4); }
private List <dynamic> ReadArrayNode(BinaryDataReader reader, int length) { List <dynamic> array = new List <dynamic>(length); // Read the element types of the array. byte[] nodeTypes = reader.ReadBytes(length); // Read the elements, which begin after a padding to the next 4 bytes. reader.Align(4); for (int i = 0; i < length; i++) { array.Add(ReadNode(reader, (ByamlNodeType)nodeTypes[i])); } return(array); }
private List <dynamic> ReadArrayNode(BinaryDataReader _reader, int length) { List <dynamic> array = new List <dynamic>(length); if (_fastLoad) { _alreadyReadNodes.Add((uint)_reader.Position - 4, array); } // Read the element types of the array. byte[] nodeTypes = _reader.ReadBytes(length); // Read the elements, which begin after a padding to the next 4 bytes. _reader.Align(4); for (int i = 0; i < length; i++) { array.Add(ReadNode(_reader, (ByamlNodeType)nodeTypes[i])); } return(array); }
public static ByamlEntry ParseArray(ByamlContext ctx, BinaryDataReader br) { List <ByamlEntry> array = new List <ByamlEntry>(); long startPos = br.Position; ByamlNodeType t = (ByamlNodeType)br.ReadByte(); if (t != ByamlNodeType.Array) { throw new ByamlException("Invalid Array"); } int count = br.ReadInt24(); List <ByamlNodeType> types = new List <ByamlNodeType>(); for (int i = 0; i < count; i++) { types.Add((ByamlNodeType)br.ReadByte()); } br.Align(4); for (int i = 0; i < count; i++) { if (!NodeIsValue(types[i])) { using (br.TemporarySeek(br.ReadUInt32(), SeekOrigin.Begin)) array.Add(ParseEntry(ctx, types[i], br)); } else { array.Add(ParseEntry(ctx, types[i], br)); } } return(new ByamlEntry(t, array)); }