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());
            }
        }