Beispiel #1
0
        public ReaderStatus ReadToArray <TElement>(ReaderState state, Func <TElement> constructor,
                                                   ReaderCallback <ReaderState, RawProtobufValue, char, TElement> callback,
                                                   out BrowserMove <TElement> browserMove)
        {
            var firstIndex = state.FieldIndex;

            browserMove = (int index, out TElement element) =>
            {
                // Read next field header if required so we know whether it's still part of the same array or not
                if (index > 0)
                {
                    state.ReadHeader();

                    // Different field index (or end of stream) was met, stop enumeration
                    if (firstIndex != state.FieldIndex)
                    {
                        element = default;

                        return(BrowserState.Success);
                    }
                }

                // Read field and continue enumeration if we're still reading elements sharing the same field index
                element = constructor();

                return(callback(this, state, ref element) != ReaderStatus.Failed
                                        ? BrowserState.Continue
                                        : BrowserState.Failure);
            };

            return(ReaderStatus.Succeeded);
        }
Beispiel #2
0
        public ReaderStatus ReadToArray <TElement>(ReaderState state, Func <TElement> constructor,
                                                   ReaderCallback <ReaderState, string, char, TElement> callback, out BrowserMove <TElement> browserMove)
        {
            browserMove = default;

            return(ReaderStatus.Ignored);
        }
Beispiel #3
0
 public ReaderStatus ReadToArray <TElement>(ReaderState state, Func <TElement> constructor,
                                            ReaderCallback <ReaderState, ProtobufValue, int, TElement> callback, out BrowserMove <TElement> browserMove)
 {
     throw new NotImplementedException();
 }
Beispiel #4
0
        public ReaderStatus ReadToArray <TElement>(ReaderState state, Func <TElement> constructor,
                                                   ReaderCallback <ReaderState, JSONValue, int, TElement> callback, out BrowserMove <TElement> browserMove)
        {
            state.PullIgnored();

            switch (state.Current)
            {
            case '[':
                browserMove = this.ReadToArrayFromArray(state, constructor, callback);

                return(ReaderStatus.Succeeded);

            case '{':
                if (this.readObjectValuesAsArray)
                {
                    browserMove = this.ReadToArrayFromObjectValues(state, constructor, callback);

                    return(ReaderStatus.Succeeded);
                }

                goto default;

            case 'n':
                browserMove = default;

                return(Reader.ExpectKeywordNull(state) ? ReaderStatus.Ignored : ReaderStatus.Failed);

            default:
                // Accept any scalar value as an array of one element
                if (this.readScalarAsOneElementArray)
                {
                    browserMove = (int index, out TElement current) =>
                    {
                        if (index > 0)
                        {
                            current = default;

                            return(BrowserState.Success);
                        }

                        current = constructor();

                        return(callback(this, state, ref current) != ReaderStatus.Failed
                                                                ? BrowserState.Continue
                                                                : BrowserState.Failure);
                    };

                    return(ReaderStatus.Succeeded);
                }

                // Ignore array when not supported by current descriptor
                else
                {
                    browserMove = (int index, out TElement current) =>
                    {
                        current = default;

                        return(BrowserState.Success);
                    };

                    return(this.Skip(state) ? ReaderStatus.Succeeded : ReaderStatus.Failed);
                }
            }
        }
Beispiel #5
0
            public void Dispose()
            {
                this.Finish();

                this.move = null;
            }
Beispiel #6
0
 public Enumerator(BrowserMove <TEntity> move)
 {
     this.index = 0;
     this.move  = move;
     this.state = BrowserState.Continue;
 }
Beispiel #7
0
 public Browser(BrowserMove <TEntity> move)
 {
     this.enumerator = new Enumerator(move);
     this.started    = false;
 }