예제 #1
0
        internal void WriteRecord(GenericFormRecord record, uint formId)
        {
            if (header == null)
            {
                throw new InvalidOperationException("Header not yet written");
            }

            FormKind formKind = (FormKind)InfoProvider.GetRecordInfo(record.GetType()).Signature;

            if (formKind != currentGroupFormKind)
            {
                // End existing group if one has begun
                if (currentGroupFormKind != FormKind.Any)
                {
                    EndSegment();
                }

                currentGroupFormKind = formKind;
                BeginGroupSegment(currentGroupFormKind);
                numRecords++;
            }

            // Convert global context Form ID to local relative Form ID
            uint localFormId = ReferenceMapper.ContexToLocal(formId);

            DoWriteRecord(record, localFormId);
            numRecords++;
        }
예제 #2
0
        private void DoReadRecord(GenericFormRecord record, bool lazyLoading)
        {
            RecordInfo recinf = InfoProvider.GetRecordInfo(record.GetType());

            if (record.GetType() != typeof(DummyRecord) && recinf.Signature != CurrentSegment.Signature)
            {
                throw new InvalidOperationException("Record signature mismatch.");
            }

            if (record.IsRecordCompressed)
            {
                // TODO: Intermediate MomeryStream may not be needed here
                long   decompressedSize = ReadUInt32();
                byte[] compressedData   = ReadBytesToEnd();
                Stream compressedStream = new MemoryStream(compressedData);
                Stream deflateStream    = new CustomDeflateStream(compressedStream, decompressedSize);
                using (RecordReader deflateReader = context.CreateReader(deflateStream))
                {
                    deflateReader.CurrentState = States.Reading;

                    // Copy flags etc to the deflate reader
                    deflateReader.PluginFlags     = PluginFlags;
                    deflateReader.ReferenceMapper = ReferenceMapper;
                    deflateReader.StringLocator   = StringLocator;

                    // Read record form the deflate reader
                    deflateReader.CurrentRecord = record;
                    record.ReadRecord(deflateReader, lazyLoading);
                    deflateReader.CurrentRecord = null;
                }
            }
            else
            {
                // Read record form the current reader
                CurrentRecord = record;
                record.ReadRecord(this, lazyLoading);
                CurrentRecord = null;
            }
        }