Exemplo n.º 1
0
        private void WriteHeaderIfRequired()
        {
            if (this.isHeaderWritten)
            {
                return;
            }

            ProtoWriter.WriteFieldHeader(1, WireType.StartGroup, this.writer);

            this.context.StartSubItem(this.resultIndex);

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

            ColumnsWriter.WriteColumns(this.context);

            this.isHeaderWritten = true;
        }
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());
            }
        }