Example #1
0
        private async Task <object> _parseAsync(TextReader reader, int maxDepth)
        {
            if (reader == null)
            {
                return(null);
            }
            if (maxDepth < 0)
            {
                maxDepth = MAX_PARSE_DEPTH;
            }

            // ???
            if (maxDepth == 0)
            {
                // Returns the original JSON string ???
                string jStr = await _readFromReaderAsync(reader);

                return(jStr);
            }

            // TBD:
            // Does this make it thread safe???
            // ...

            JsonTokenizer jsonTokenizer = null;

            if (threadSafe)
            {
                // ???
                jsonTokenizer = new AbstractJsonTokenizerAnonymousInnerClass(this, reader, parserPolicy);
                SetLookAheadParsing(jsonTokenizer);
                SetTokenizerTracing(jsonTokenizer);
            }
            else
            {
                if (mJsonTokenizer != null && mJsonTokenizer is AbstractJsonTokenizer)
                {
                    ((AbstractJsonTokenizer)mJsonTokenizer).Reset(reader);
                }
                else
                {
                    mJsonTokenizer = new AbstractJsonTokenizerAnonymousInnerClass2(this, reader, parserPolicy);
                    SetLookAheadParsing(mJsonTokenizer);
                    SetTokenizerTracing(mJsonTokenizer);
                }
                jsonTokenizer = mJsonTokenizer;
            }

            JsonTokenBuffer tokenTailBuffer = null;

            if (threadSafe)
            {
                tokenTailBuffer = new JsonTokenBuffer(DEF_TOKEN_TAIL_BUFFER_SIZE);
            }
            else
            {
                if (mTokenTailBuffer != null)
                {
                    mTokenTailBuffer.Reset();
                }
                else
                {
                    mTokenTailBuffer = new JsonTokenBuffer(DEF_TOKEN_TAIL_BUFFER_SIZE);
                }
                tokenTailBuffer = mTokenTailBuffer;
            }

            ObjectTailBuffer nodeTailBuffer = null;

            if (threadSafe)
            {
                nodeTailBuffer = new ObjectTailBuffer(DEF_NODE_TAIL_BUFFER_SIZE);
            }
            else
            {
                if (mNodeTailBuffer != null)
                {
                    mNodeTailBuffer.Reset();
                }
                else
                {
                    mNodeTailBuffer = new ObjectTailBuffer(DEF_NODE_TAIL_BUFFER_SIZE);
                }
                nodeTailBuffer = mNodeTailBuffer;
            }

            return(await _parseAsync(jsonTokenizer, maxDepth, tokenTailBuffer, nodeTailBuffer));
        }
        private object _parse(TextReader reader)
        {
            if (reader == null)
            {
                return(null);
            }

            // TBD:
            // Does this make it thread safe???
            // ...

            JsonTokenizer jsonTokenizer = null;

            if (threadSafe)
            {
                // ???
                //jsonTokenizer = new AbstractJsonTokenizer(reader, parserPolicy) {};
                jsonTokenizer = new SimpleJsonTokenizer(reader, parserPolicy);
                SetLookAheadParsing(jsonTokenizer);
                SetTokenizerTracing(jsonTokenizer);
            }
            else
            {
                if (mJsonTokenizer != null && mJsonTokenizer is AbstractJsonTokenizer)
                {
                    ((AbstractJsonTokenizer)mJsonTokenizer).Reset(reader);
                }
                else
                {
                    // mJsonTokenizer = new AbstractJsonTokenizer(reader, parserPolicy) {};
                    mJsonTokenizer = new SimpleJsonTokenizer(reader, parserPolicy);
                    SetLookAheadParsing(mJsonTokenizer);
                    SetTokenizerTracing(mJsonTokenizer);
                }
                jsonTokenizer = mJsonTokenizer;
            }

            JsonTokenBuffer tokenTailBuffer = null;

            if (threadSafe)
            {
                tokenTailBuffer = new JsonTokenBuffer(DEF_TOKEN_TAIL_BUFFER_SIZE);
            }
            else
            {
                if (mTokenTailBuffer != null)
                {
                    mTokenTailBuffer.Reset();
                }
                else
                {
                    mTokenTailBuffer = new JsonTokenBuffer(DEF_TOKEN_TAIL_BUFFER_SIZE);
                }
                tokenTailBuffer = mTokenTailBuffer;
            }

            ObjectTailBuffer nodeTailBuffer = null;

            if (threadSafe)
            {
                nodeTailBuffer = new ObjectTailBuffer(DEF_NODE_TAIL_BUFFER_SIZE);
            }
            else
            {
                if (mNodeTailBuffer != null)
                {
                    mNodeTailBuffer.Reset();
                }
                else
                {
                    mNodeTailBuffer = new ObjectTailBuffer(DEF_NODE_TAIL_BUFFER_SIZE);
                }
                nodeTailBuffer = mNodeTailBuffer;
            }

            return(_parse(jsonTokenizer, tokenTailBuffer, nodeTailBuffer));
        }