public static RecordType GetNextRecordType(IStreamReader reader) { long position = reader.BaseStream.Position; // read type of the next record var nextRecord = (RecordType)reader.ReadUInt16(); ushort length = reader.ReadUInt16(); // skip leading StartBlock/EndBlock records if (nextRecord == RecordType.StartBlock || nextRecord == RecordType.EndBlock || nextRecord == RecordType.StartObject || nextRecord == RecordType.EndObject || nextRecord == RecordType.ChartFrtInfo) { // skip the body of the record reader.ReadBytes(length); // get the type of the next record return(GetNextRecordType(reader)); } else if (nextRecord == RecordType.FrtWrapper) { // return type of wrapped Biff record var frtWrapper = new FrtWrapper(reader, nextRecord, length); reader.BaseStream.Position = position; return(frtWrapper.wrappedRecord.Id); } else { // seek back to the begin of the current record reader.BaseStream.Position = position; return(nextRecord); } }
public static BiffRecord ReadRecord(IStreamReader reader) { BiffRecord result = null; try { var id = (RecordType)reader.ReadUInt16(); ushort length = reader.ReadUInt16(); // skip leading StartBlock/EndBlock records if (id == RecordType.StartBlock || id == RecordType.EndBlock || id == RecordType.StartObject || id == RecordType.EndObject || id == RecordType.ChartFrtInfo) { // skip the body of this record reader.ReadBytes(length); // get the next record return(ReadRecord(reader)); } else if (id == RecordType.FrtWrapper) { // return type of wrapped Biff record var frtWrapper = new FrtWrapper(reader, id, length); return(frtWrapper.wrappedRecord); } Type cls; if (TypeToRecordClassMapping.TryGetValue((ushort)id, out cls)) { var constructor = cls.GetConstructor( new Type[] { typeof(IStreamReader), typeof(RecordType), typeof(ushort) } ); try { result = (BiffRecord)constructor.Invoke( new object[] { reader, id, length } ); } catch (TargetInvocationException e) { throw e.InnerException; } } else { result = new UnknownBiffRecord(reader, (RecordType)id, length); } return(result); } catch (OutOfMemoryException e) { throw new Exception("Invalid BIFF record", e); } }