コード例 #1
0
        static void DeserializeArrayThunkReader(ref ThunkReader reader, ObjectBuilder builder)
        {
            int c;

            builder.StartArray();

            while (true)
            {
                Methods.ConsumeWhiteSpaceThunkReader(ref reader);

                c = reader.Peek();
                if (c == -1)
                {
                    throw new DeserializationException("Unexpected end of stream", ref reader, true);
                }
                if (c == ']')
                {
                    reader.Read();  // skip the ]
                    break;
                }

                _DeserializeMemberThunkReader(ref reader, builder);
                Methods.ConsumeWhiteSpaceThunkReader(ref reader);
                c = reader.Read();

                if (c == ',')
                {
                    continue;
                }
                if (c == ']')
                {
                    break;
                }

                throw new DeserializationException("Expected , or ], found " + (char)c, ref reader, c == -1);
            }

            builder.EndArray();
        }
コード例 #2
0
        static void _DeserializeMemberThunkReader(ref ThunkReader reader, ObjectBuilder builder)
        {
            Methods.ConsumeWhiteSpaceThunkReader(ref reader);

            var c = reader.Read();

            switch (c)
            {
            case '"': DeserializeStringThunkReader(ref reader, builder); return;

            case '[': DeserializeArrayThunkReader(ref reader, builder); return;

            case '{': DeserializeObjectThunkReader(ref reader, builder); return;

            case 'n': DeserializeNullThunkReader(ref reader, builder); return;

            case 't': DeserializeTrueThunkReader(ref reader, builder); return;

            case 'f': DeserializeFalseThunkReader(ref reader, builder); return;

            case '-': DeserializeNumberThunkReader('-', ref reader, builder); return;
            }

            if (c >= '0' && c <= '9')
            {
                DeserializeNumberThunkReader((char)c, ref reader, builder);
                return;
            }

            if (c == -1)
            {
                throw new DeserializationException("Unexpected end of stream", ref reader, true);
            }

            throw new DeserializationException("Expected \", [, {, n, t, f, -, 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9; found " + (char)c, ref reader, false);
        }
コード例 #3
0
        static void DeserializeObjectThunkReader(ref ThunkReader reader, ObjectBuilder builder)
        {
            int c;

            builder.StartObject();

            while (true)
            {
                Methods.ConsumeWhiteSpaceThunkReader(ref reader);

                c = reader.Peek();
                if (c == -1)
                {
                    throw new DeserializationException("Unexpected end of stream", ref reader, true);
                }
                if (c == '}')
                {
                    reader.Read();  // skip }
                    break;
                }

                c = reader.Read();
                if (c == -1)
                {
                    throw new DeserializationException("Unexpected end of stream", ref reader, true);
                }
                if (c != '"')
                {
                    throw new DeserializationException("Expected \", found " + (char)c, ref reader, false);
                }

                builder.StartObjectMember();
                DeserializeStringThunkReader(ref reader, builder);

                Methods.ConsumeWhiteSpaceThunkReader(ref reader);
                c = reader.Read();
                if (c == -1)
                {
                    throw new DeserializationException("Unexpected end of stream", ref reader, true);
                }
                if (c != ':')
                {
                    throw new DeserializationException("Expected :, found " + (char)c, ref reader, false);
                }

                _DeserializeMemberThunkReader(ref reader, builder);

                builder.EndObjectMember();

                Methods.ConsumeWhiteSpaceThunkReader(ref reader);
                c = reader.Read();

                if (c == ',')
                {
                    continue;
                }
                if (c == '}')
                {
                    break;
                }

                if (c == -1)
                {
                    throw new DeserializationException("Unexpected end of stream", ref reader, true);
                }

                throw new DeserializationException("Expected , or }, found " + (char)c, ref reader, false);
            }

            builder.EndObject();
        }