Exemplo n.º 1
0
        public static void WriteColumns(ProtoWriterContext context)
        {
            foreach (var column in context.Columns)
            {
                ProtoWriter.WriteFieldHeader(ColumnFieldHeader, WireType.StartGroup, context.Writer);

                context.StartSubItem(column);

                WriteColumnName(context, column);
                WriteColumnType(context, column);

                context.EndSubItem();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Serialize an <see cref="System.Data.IDataReader"/> to a binary stream using protocol-buffers.
        /// </summary>
        /// <param name="stream">The <see cref="System.IO.Stream"/> to write to.</param>
        /// <param name="reader">The <see cref="System.Data.IDataReader"/>who's contents to serialize.</param>
        /// <param name="options"><see cref="ProtoDataWriterOptions"/> specifying any custom serialization options.</param>
        public void Serialize(Stream stream, IDataReader reader, ProtoDataWriterOptions options)
        {
            Throw.IfNull(stream, nameof(stream));
            Throw.IfNull(reader, nameof(reader));

            options = options ?? new ProtoDataWriterOptions();

            var resultIndex = 0;

            using (var writer = new ProtoWriter(stream, null, null))
            {
                var context = new ProtoWriterContext(writer, options);

                do
                {
                    ProtoWriter.WriteFieldHeader(1, WireType.StartGroup, writer);

                    context.StartSubItem(resultIndex);

                    context.Columns = ProtoDataColumnFactory.GetColumns(reader, options);

                    ColumnsWriter.WriteColumns(context);

                    var recordIndex = 0;

                    while (reader.Read())
                    {
                        RecordWriter.WriteRecord(context, recordIndex, reader);

                        recordIndex++;
                    }

                    context.EndSubItem();

                    resultIndex++;
                }while (reader.NextResult());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProtoDataStream"/> class.
        /// </summary>
        /// <param name="reader">The <see cref="IDataReader"/>who's contents to serialize.</param>
        /// <param name="options"><see cref="ProtoDataWriterOptions"/> specifying any custom serialization options.</param>
        /// <param name="bufferSize">Buffer size to use when serializing rows.
        /// You should not need to change this unless you have exceptionally
        /// large rows or an exceptionally high number of columns.</param>
        public ProtoDataStream(
            IDataReader reader,
            ProtoDataWriterOptions options,
            int bufferSize = DefaultBufferSize)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            this.reader  = reader;
            this.options = options;

            this.resultIndex  = 0;
            this.bufferStream = new CircularStream(bufferSize);
            this.writer       = ProtoWriter.Create(this.bufferStream, null, null);
            this.context      = new ProtoWriterContext(this.writer, this.options);
        }
Exemplo n.º 4
0
 private static void WriteColumnType(ProtoWriterContext context, ProtoDataColumn column)
 {
     ProtoWriter.WriteFieldHeader(ColumnTypeFieldHeader, WireType.Variant, context.Writer);
     ProtoWriter.WriteInt32((int)column.ProtoDataType, context.Writer);
 }
Exemplo n.º 5
0
 private static void WriteColumnName(ProtoWriterContext context, ProtoDataColumn column)
 {
     ProtoWriter.WriteFieldHeader(ColumnNameFieldHeader, WireType.String, context.Writer);
     ProtoWriter.WriteString(column.Name, context.Writer);
 }