Ejemplo n.º 1
0
            internal void SaveRecord(IBedRecord rec)
            {
                long pos0 = Data.Length;

                BedTool.SaveRecord(rec.FieldCount, rec, m_writer);
                Lengths.Add((int)(Data.Length - pos0));
            }
Ejemplo n.º 2
0
        public static void WriteQueueToStream(IDataQueue queue, Stream fw, BedDataStats stats)
        {
            BinaryWriter bw = new BinaryWriter(fw);

            bw.Write(SIGNATURE);
            bw.Write((int)2); // version
            var ts = queue.GetRowFormat;

            bw.Write7BitEncodedInt(ts.Columns.Count);

            var pk = ts.FindConstraint <IPrimaryKey>();

            foreach (IColumnStructure col in ts.Columns)
            {
                bw.Write(col.ColumnName);
                bw.Write((byte)col.DataType.DefaultStorage);
                ColFlags flags = 0;
                if (pk != null && pk.Columns.IndexOfIf(c => c.ColumnName == col.ColumnName) >= 0)
                {
                    flags |= ColFlags.ISPK;
                }
                bw.Write((byte)flags);
            }

            MemoryStream rowdata = new MemoryStream();
            BinaryWriter bwrow   = new BinaryWriter(rowdata);

            try
            {
                while (!queue.IsEof)
                {
                    rowdata.Position = 0;
                    rowdata.SetLength(0);
                    IBedRecord row = queue.GetRecord();
                    BedTool.SaveRecord(ts.Columns.Count, row, bwrow);
                    bw.Write7BitEncodedInt((int)rowdata.Length);
                    rowdata.WriteTo(bw.BaseStream);
                    if (stats != null)
                    {
                        stats.Rows++;
                        stats.Bytes += (int)rowdata.Length;
                        stats.Bytes += 4;
                    }
                }
            }
            finally
            {
                queue.CloseReading();
            }
            // write EOF mark
            bw.Write7BitEncodedInt(-1);
        }