Exemple #1
0
        public static TpsRecord GetRecord(Stream inputStream, TpsRecord previous)
        {
            var buffer = new byte[2];
            var flags  = (byte)inputStream.ReadByte();

            short recordLength;
            short headerLength;

            if ((flags & 0x80) != 0)
            {
                inputStream.Read(buffer, 0, 2);
                recordLength = BitUtil.ToInt16(buffer, 0);
            }
            else
            {
                recordLength = (short)(previous.Data.Length + previous.Header.Length);
            }
            if ((flags & 0x40) != 0)
            {
                inputStream.Read(buffer, 0, 2);
                headerLength = BitUtil.ToInt16(buffer, 0);
            }
            else
            {
                headerLength = (short)previous.Header.Length;
            }
            var copy = flags & 0x3F;

            byte[] allData;
            try
            {
                allData = new byte[recordLength];
                if (copy > 0)
                {
                    Array.Copy(previous.Header, 0, allData, 0,
                               copy > previous.Header.Length ? previous.Header.Length : copy);
                    if (copy > previous.Header.Length)
                    {
                        Array.Copy(previous.Data, 0, allData, previous.Header.Length, copy - previous.Header.Length);
                    }
                }
                inputStream.Read(allData, copy, allData.Length - copy);
            }
            catch (Exception ex)
            {
                throw new InvalidOperationException(
                          "When reading " + (recordLength - copy) + " bytes of TpsRecord at " +
                          inputStream.Position, ex);
            }

            var header = new byte[headerLength];
            var data   = new byte[recordLength - headerLength];

            Array.Copy(allData, 0, header, 0, headerLength);
            Array.Copy(allData, headerLength, data, 0, recordLength - headerLength);

            return(CreateRecord(header, data));
        }
Exemple #2
0
        public void ParseRecords()
        {
            if (IsFlushed())
            {
                Uncompress();
            }
            Records.Clear();
            // Skip pages with non 0x00 flags as they don't seem to contain TpsRecords.
            if (Flags == 0x00)
            {
                using (var stream = new MemoryStream(_data))
                {
                    TpsRecord prev = null;
                    do
                    {
                        var current = prev == null?TpsRecord.GetRecord(stream) : TpsRecord.GetRecord(stream, prev);

                        Records.Add(current);
                        prev = current;
                    } while (stream.Position != stream.Length - 1 && Records.Count < RecordCount);
                }
            }
        }