예제 #1
0
        protected ReaderBase(BoundConfigurationBase <T> config, object context)
        {
            RowNumber     = 0;
            Configuration = config;
            Context       = context;

            var bufferSize = config.ReadBufferSizeHint;

            if (bufferSize == 0)
            {
                bufferSize = DEFAULT_BUFFER_SIZE;
            }

            Buffer  = new BufferWithPushback(config.MemoryPool, bufferSize);
            Partial = new Partial <T>(config.MemoryPool);

            SharedCharacterLookup =
                ReaderStateMachine.MakeCharacterLookup(
                    config.MemoryPool,
                    config.EscapedValueStartAndStop,
                    config.ValueSeparator,
                    config.EscapeValueEscapeChar,
                    config.CommentChar
                    );
        }
예제 #2
0
        protected WriterBase(BoundConfigurationBase <T> config, object?context)
        {
            RowNumber     = 0;
            Configuration = config;

            var options       = Configuration.Options;
            var memPool       = Configuration.MemoryPool;
            var writeSizeHint = options.WriteBufferSizeHint;

            Buffer  = new MaxSizedBufferWriter(memPool, writeSizeHint);
            Context = context;

            // buffering is configurable
            if (writeSizeHint == 0)
            {
                HasStaging    = false;
                Staging       = EmptyMemoryOwner.Singleton;
                StagingMemory = Memory <char> .Empty;
                InStaging     = -1;
            }
            else
            {
                HasStaging    = true;
                Staging       = memPool.Rent(writeSizeHint ?? MaxSizedBufferWriter.DEFAULT_STAGING_SIZE);
                StagingMemory = Staging.Memory;
                InStaging     = 0;
            }

            IsFirstRow    = true;
            Columns       = Array.Empty <Column>();
            WriteContexts = Array.Empty <WriteContext>();
        }
예제 #3
0
        internal HeadersReader(
            BoundConfigurationBase <T> config,
            ReaderStateMachine.CharacterLookup charLookup,
            TextReader inner,
            BufferWithPushback buffer
            )
        {
            MemoryPool     = config.MemoryPool;
            BufferSizeHint = config.ReadBufferSizeHint;
            Columns        = config.DeserializeColumns;
            Inner          = inner;

            StateMachine =
                new ReaderStateMachine(
                    charLookup,
                    config.EscapedValueStartAndStop,
                    config.EscapeValueEscapeChar,
                    config.RowEnding,
                    ReadHeaders.Never
                    );

            Buffer = buffer;

            HeaderCount    = 0;
            PushBackLength = 0;
        }
예제 #4
0
 internal HeadersReader(
     ReaderStateMachine stateMachine,
     BoundConfigurationBase <T> config,
     CharacterLookup charLookup,
     IAsyncReaderAdapter inner,
     BufferWithPushback buffer,
     ReadRowEnding rowEndingOverride
     )
     : this(stateMachine, config, charLookup, null, inner, buffer, rowEndingOverride)
 {
 }
예제 #5
0
        protected WriterBase(BoundConfigurationBase <T> config, object context)
        {
            RowNumber = 0;
            Config    = config;
            Buffer    = new MaxSizedBufferWriter(Config.MemoryPool, config.WriteBufferSizeHint);
            Context   = context;

            // buffering is configurable
            if (Config.WriteBufferSizeHint == 0)
            {
                Staging   = null;
                InStaging = -1;
            }
            else
            {
                InStaging = 0;
                Staging   = Config.MemoryPool.Rent(Config.WriteBufferSizeHint ?? MaxSizedBufferWriter.DEFAULT_STAGING_SIZE);
            }
        }
예제 #6
0
        private HeadersReader(
            ReaderStateMachine stateMachine,
            BoundConfigurationBase <T> config,
            CharacterLookup charLookup,
            IReaderAdapter?inner,
            IAsyncReaderAdapter?innerAsync,
            BufferWithPushback buffer,
            ReadRowEnding rowEndingOverride
            )
        {
            LogHelper.StateTransition_NewHeadersReader();

            Configuration = config;

            Inner.SetAllowNull(inner);
            InnerAsync.SetAllowNull(innerAsync);

            var options = Configuration.Options;

            MemoryPool     = Configuration.MemoryPool;
            BufferSizeHint = options.ReadBufferSizeHint;
            Columns        = config.DeserializeColumns;

            StateMachine = stateMachine;
            stateMachine.Initialize(
                charLookup,
                options.EscapedValueStartAndEnd,
                options.EscapedValueEscapeCharacter,
                rowEndingOverride,                      // this can be something OTHER than what was provided, due to RowEnding.Detect
                ReadHeader.Never,
                false,
                options.WhitespaceTreatment.HasFlag(WhitespaceTreatments.TrimBeforeValues),
                options.WhitespaceTreatment.HasFlag(WhitespaceTreatments.TrimAfterValues)
                );

            Buffer = buffer;

            HeaderCount         = 0;
            PushBackLength      = 0;
            WhitespaceTreatment = options.WhitespaceTreatment;
        }
예제 #7
0
        protected ReaderBase(BoundConfigurationBase <T> config, object?context, IRowConstructor <T> rowBuilder, ExtraColumnTreatment extraTreatment)
        {
            RowNumber     = 0;
            Configuration = config;
            Context       = context;

            var options = config.Options;

            var bufferSize = options.ReadBufferSizeHint;

            if (bufferSize == 0)
            {
                bufferSize = Utils.DEFAULT_BUFFER_SIZE;
            }

            // always need to be able to store a whole value separator "character"
            var bufferMinSize = config.ValueSeparatorMemory.Length * 2;

            if (bufferSize < bufferMinSize)
            {
                bufferSize = bufferMinSize;
            }

            var memPool = config.MemoryPool;

            Buffer =
                new BufferWithPushback(
                    memPool,
                    bufferSize
                    );
            Partial = new Partial(memPool);

            SharedCharacterLookup = CharacterLookup.MakeCharacterLookup(options, out _);
            StateMachine          = new ReaderStateMachine();
            RowBuilder            = rowBuilder;

            ExtraColumnTreatment = extraTreatment;
        }
예제 #8
0
        internal RowEndingDetector(BoundConfigurationBase <T> config, ReaderStateMachine.CharacterLookup charLookup, TextReader inner)
        {
            Inner = inner;

            State =
                new ReaderStateMachine(
                    charLookup,
                    config.EscapedValueStartAndStop,
                    config.EscapeValueEscapeChar,
                    RowEndings.None,
                    ReadHeaders.Never
                    );

            MemoryPool = config.MemoryPool;

            BufferSizeHint = config.ReadBufferSizeHint;
            if (BufferSizeHint == 0)
            {
                BufferSizeHint = ReaderBase <T> .DEFAULT_BUFFER_SIZE;
            }

            BufferOwner = MemoryPool.Rent(BufferSizeHint);
            BufferStart = 0;
        }
예제 #9
0
 internal AsyncWriterBase(BoundConfigurationBase <T> config, IAsyncWriterAdapter inner, object?context) : base(config, context)
 {
     Inner = inner;
 }
예제 #10
0
 internal SyncReaderBase(IReaderAdapter inner, BoundConfigurationBase <T> config, object?context, IRowConstructor <T> rowBuilder, ExtraColumnTreatment extraTreatment) : base(config, context, rowBuilder, extraTreatment)
 {
     Inner = inner;
 }