public Record(byte[] data, int pointer, bool isQuestion = false) { var previousePointer = pointer; Name = GetName(data, ref pointer); QType = MyBitConverter.ToUInt16(data, ref pointer); if (!availableTypes.Contains(QType)) { throw new Exception($"Incorrect type {QType}"); } QClass = MyBitConverter.ToUInt16(data, ref pointer); if (isQuestion) { LengthRecord = pointer - previousePointer; Pointer = pointer; return; } Ttl = MyBitConverter.ToUInt32(data, ref pointer); DataLenght = MyBitConverter.ToUInt16(data, ref pointer); PointerToData = (ushort)pointer; Data = data.Skip(pointer).Take(DataLenght); Pointer = pointer + DataLenght; LengthRecord = Pointer - previousePointer; }
/// <summary> /// Loads TIFF header from stream. /// </summary> /// <param name="stream">Fully formatted TIFF image.</param> /// <returns>Length of header.</returns> protected override long Load(Stream stream) { base.Load(stream); byte[] temp = stream.ReadBytes(8); if (!CheckIdentifier(temp)) { throw new FormatException("Stream is not a recognised TIFF image."); } // Change byte order if required. if (temp[0] == 'M') { endianness = MyBitConverter.Endianness.BigEndian; } // Header FirstImageOffset = MyBitConverter.ToUInt32(temp, 4, endianness); stream.Seek(FirstImageOffset, SeekOrigin.Begin); var IFD = new ImageFileDirectory(stream, endianness); Pages = new List <ImageFileDirectory>() { IFD }; // Add mipmaps if they exist while (IFD.NextIFDOffset != 0) { IFD = new ImageFileDirectory(stream, endianness); Pages.Add(IFD); } return(0); // No sensible return value since header is not contiguous (right?) }