Exemple #1
0
        public MstRecord ReadRecord2
        (
            long offset
        )
        {
            if (_stream.Seek(offset, SeekOrigin.Begin) != offset)
            {
                throw new IOException();
            }

            Encoding encoding = new UTF8Encoding(false, true);

            MemoryStream memory = new MemoryStream(PreloadLength);

            _AppendStream(_stream, memory, PreloadLength);
            memory.Position = 0;

            MstRecordLeader leader       = MstRecordLeader.Read(memory);
            int             amountToRead = (int)(leader.Length - memory.Length);

            if (amountToRead > 0)
            {
                _AppendStream(_stream, memory, amountToRead);
            }

            List <MstDictionaryEntry> dictionary
                = new List <MstDictionaryEntry>();

            for (int i = 0; i < leader.Nvf; i++)
            {
                MstDictionaryEntry entry = new MstDictionaryEntry
                {
                    Tag      = memory.ReadInt32Network(),
                    Position = memory.ReadInt32Network(),
                    Length   = memory.ReadInt32Network()
                };
                dictionary.Add(entry);
            }

            foreach (MstDictionaryEntry entry in dictionary)
            {
                long endOffset = leader.Base + entry.Position;
                memory.Seek(endOffset, SeekOrigin.Begin);
                entry.Bytes = memory.ReadBytes(entry.Length);
                if (entry.Bytes != null)
                {
                    entry.Text = encoding.GetString(entry.Bytes);
                }
            }

            MstRecord result = new MstRecord
            {
                Leader     = leader,
                Dictionary = dictionary
            };

            return(result);
        }
Exemple #2
0
        public RecordField DecodeField(MstDictionaryEntry entry)
        {
            string catenated = string.Format
                               (
                "{0}#{1}",
                entry.Tag,
                entry.Text
                               );

            RecordField result = RecordField.Parse(catenated);

            return(result);
        }
Exemple #3
0
        public MstRecord ReadRecord(long offset)
        {
            if (_stream.Seek(offset, SeekOrigin.Begin) != offset)
            {
                throw new IOException();
            }

            //new ObjectDumper()
            //    .DumpStream(_stream,offset,64)
            //    .WriteLine();

            Encoding encoding = new UTF8Encoding(false, true);

            MstRecordLeader leader = MstRecordLeader.Read(_stream);

            List <MstDictionaryEntry> dictionary
                = new List <MstDictionaryEntry> ();

            for (int i = 0; i < leader.Nvf; i++)
            {
                MstDictionaryEntry entry = new MstDictionaryEntry
                {
                    Tag      = _stream.ReadInt32Network(),
                    Position = _stream.ReadInt32Network(),
                    Length   = _stream.ReadInt32Network()
                };
                dictionary.Add(entry);
            }

            foreach (MstDictionaryEntry entry in dictionary)
            {
                long endOffset = offset + leader.Base + entry.Position;
                _stream.Seek(endOffset, SeekOrigin.Begin);
                entry.Bytes = _stream.ReadBytes(entry.Length);
                if (entry.Bytes != null)
                {
                    entry.Text = encoding.GetString(entry.Bytes);
                }
            }

            MstRecord result = new MstRecord
            {
                Leader     = leader,
                Dictionary = dictionary
            };

            return(result);
        }