Ejemplo n.º 1
0
        public void ReadObject(IDataWriter <string> valueWriter)
        {
            try
            {
                valueWriter.Initialize();

                if (valueWriter.Count >= 0)
                {
                    foreach (var name in valueWriter.Keys)
                    {
                        valueWriter.OnWriteValue(name, this);
                    }
                }
                else
                {
                    for (int i = ReadByte(); i >= 0; i--)
                    {
                        valueWriter.OnWriteValue(ReadString(), this);
                    }
                }
            }
            catch
            {
                if (valueWriter.ContentType != null)
                {
                    valueWriter.Content = TypeHelper.GetDefaultValue(valueWriter.ContentType);
                }
            }
        }
Ejemplo n.º 2
0
        public void ReadObject(IDataWriter <string> valueWriter)
        {
            var size = TryReadMapHead();

            if (size >= 0)
            {
                valueWriter.Initialize(size);

                if (valueWriter is IId64DataRW <byte> fastWriter)
                {
                    for (int i = 0; i < size; i++)
                    {
                        var bytesLength = TryReadStringHead();

                        if (bytesLength >= 0)
                        {
                            var id64 = fastWriter.GetId64(ref current[0], bytesLength);

                            current += bytesLength;

                            fastWriter.OnWriteValue(id64, this);
                        }
                        else
                        {
                            valueWriter.OnWriteValue(ReadString(), this);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < size; i++)
                    {
                        valueWriter.OnWriteValue(ReadString(), this);
                    }
                }


                return;
            }

            if (TryReadNull())
            {
                return;
            }

            if (IsArrayHead())
            {
                ReadArray(valueWriter.As <int>());

                return;
            }

            throw new InvalidOperationException("The msgpack node is not an object.");
        }
Ejemplo n.º 3
0
        public override void ReadArray(IDataWriter <int> valueWriter)
        {
            switch (state)
            {
            case ReadState.Table:

                state = ReadState.Row;

                if (!FastObjectArrayCollectionInvoker.TryReadTo(dbDataReader, valueWriter))
                {
                    valueWriter.Initialize();

                    for (int i = 0; dbDataReader.Read(); i++)
                    {
                        valueWriter.OnWriteValue(i, this);
                    }
                }

                state = ReadState.Finish;

                break;

            case ReadState.Row:
                state = ReadState.Value;

                valueWriter.Initialize();

                for (ordinal = 0; ordinal < dbDataReader.FieldCount; ordinal++)
                {
                    valueWriter.OnWriteValue(ordinal, this);
                }

                state = ReadState.Row;

                break;

            case ReadState.Value:
                base.ReadArray(valueWriter);

                break;

            default:
                if (dbDataReader.NextResult())
                {
                    goto case ReadState.Table;
                }

                throw new ArgumentException("Finish");
            }
        }
Ejemplo n.º 4
0
        public override void ReadObject(IDataWriter <string> valueWriter)
        {
            switch (state)
            {
            case ReadState.Table:
                state = ReadState.Value;

                if (dbDataReader.Read())
                {
                    valueWriter.Initialize();

                    for (ordinal = 0; ordinal < dbDataReader.FieldCount; ordinal++)
                    {
                        valueWriter.OnWriteValue(dbDataReader.GetName(ordinal), this);
                    }
                }

                state = ReadState.Finish;

                break;

            case ReadState.Row:
                state = ReadState.Value;

                valueWriter.Initialize();

                for (ordinal = 0; ordinal < dbDataReader.FieldCount; ordinal++)
                {
                    valueWriter.OnWriteValue(dbDataReader.GetName(ordinal), this);
                }

                state = ReadState.Row;

                break;

            case ReadState.Value:
                base.ReadObject(valueWriter);

                break;

            default:
                if (dbDataReader.NextResult())
                {
                    goto case ReadState.Table;
                }

                throw new ArgumentException("Finish");
            }
        }
Ejemplo n.º 5
0
        public void ReadArray(IDataWriter <int> valueWriter)
        {
            var length = TryReadArrayHead();

            if (length >= 0)
            {
                valueWriter.Initialize(length);

                for (int i = 0; i < length; i++)
                {
                    valueWriter.OnWriteValue(i, this);
                }

                return;
            }

            if (TryReadNull())
            {
                return;                // Null direct return;
            }
            if (IsMapHead())
            {
                ReadMap(valueWriter);

                return;
            }

            throw new InvalidOperationException("The msgpack node is not an array.");
        }
Ejemplo n.º 6
0
        public void ReadMap <TKey>(IDataWriter <TKey> mapWriter)
        {
            var length = TryReadMapHead();

            if (length >= 0)
            {
                mapWriter.Initialize(length);

                for (int i = 0; i < length; i++)
                {
                    mapWriter.OnWriteValue(ValueInterface <TKey> .ReadValue(this), this);
                }

                return;
            }

            if (TryReadNull())
            {
                return;
            }

            if (IsArrayHead())
            {
                ReadArray(mapWriter.As <int>());

                return;
            }

            throw new InvalidOperationException("The msgpack node is not a map.");
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获取数据写入器中指定键的值的类型。
        /// </summary>
        /// <typeparam name="TKey">键类型</typeparam>
        /// <param name="dataWriter">数据写入器</param>
        /// <param name="key">指定键</param>
        /// <returns>返回一个类型</returns>
        public static Type GetItemType <TKey>(IDataWriter <TKey> dataWriter, TKey key)
        {
            var auxiliary = new AuxiliaryValueRW();

            dataWriter.OnWriteValue(key, auxiliary);

            return(auxiliary.GetValueType());
        }
Ejemplo n.º 8
0
        public void ReadObject(IDataWriter <string> valueWriter)
        {
            valueWriter.Initialize();

            if (valueWriter.Keys != null)
            {
                foreach (var key in valueWriter.Keys)
                {
                    valueWriter.OnWriteValue(key, this);
                }
            }
            else
            {
                for (int i = RandomInstance.Next(MinObjectSize, MaxObjectSize); i >= 0; --i)
                {
                    valueWriter.OnWriteValue(ReadString(), this);
                }
            }
        }
Ejemplo n.º 9
0
        public void ReadArray(IDataWriter <int> valueWriter)
        {
            valueWriter.Initialize();

            if (valueWriter.Count != 0 && valueWriter.Keys != null)
            {
                foreach (var key in valueWriter.Keys)
                {
                    valueWriter.OnWriteValue(key, this);
                }
            }
            else
            {
                var length = RandomInstance.Next(MinArraySize, MaxArraySize);

                for (int i = 0; i < length; i++)
                {
                    valueWriter.OnWriteValue(i, this);
                }
            }
        }
Ejemplo n.º 10
0
        public override void ReadArray(IDataWriter <int> dataWriter)
        {
            if (!IsArray)
            {
                NoObjectOrArray(dataWriter);

                return;
            }

            var i = 0;

            ++current;

            dataWriter.Initialize();

Loop:

            SkipWhiteSpace();

            if (current < end)
            {
                if (*current == ']')
                {
                    goto Return;
                }

                dataWriter.OnWriteValue(i, this); ++i;

                SkipWhiteSpace();

                if (current < end)
                {
                    switch (*current)
                    {
                    case ']':
                        goto Return;

                    case ',':
                        ++current;

                        goto Loop;
                    }
                }
            }

            throw GetException();

Return:

            ++current;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 获取数据写入器中指定键的值的类型。
        /// </summary>
        /// <typeparam name="TKey">键类型</typeparam>
        /// <param name="dataWriter">数据写入器</param>
        /// <param name="key">指定键</param>
        /// <returns>返回一个类型</returns>
        public static Type GetItemType <TKey>(IDataWriter <TKey> dataWriter, TKey key)
        {
            var auxiliary = new AuxiliaryValueRW();

            if (typeof(TKey) == typeof(long) && ((dataWriter as IAsDataWriter)?.Content ?? dataWriter) is IId64DataRW id64DataRW)
            {
                id64DataRW.OnWriteValue(Unsafe.As <TKey, long>(ref key), auxiliary);
            }
            else
            {
                dataWriter.OnWriteValue(key, auxiliary);
            }

            return(auxiliary.GetType());
        }
Ejemplo n.º 12
0
        public void ReadArray(IDataWriter <int> valueWriter)
        {
            valueWriter.Initialize();

            if (readed || dbDataReader.Read())
            {
                readed = true;

                int i = 0;

                do
                {
                    valueWriter.OnWriteValue(i, this);

                    ++i;
                } while (dbDataReader.Read());
            }
        }
Ejemplo n.º 13
0
        public void ReadArray(IDataWriter <int> valueWriter)
        {
            try
            {
                var count = random.Next(0, 300);

                valueWriter.Initialize(count);

                for (int i = 0; i < count; i++)
                {
                    valueWriter.OnWriteValue(i, this);
                }
            }
            catch
            {
                if (valueWriter.ContentType != null)
                {
                    valueWriter.Content = TypeHelper.GetDefaultValue(valueWriter.ContentType);
                }
            }
        }
Ejemplo n.º 14
0
        void IValueReader.ReadObject(IDataWriter <string> valueWriter)
        {
            switch (GetValueType())
            {
            case JsonValueTypes.String:
                throw new InvalidCastException("Cannot convert String to object.");

            case JsonValueTypes.Number:
                throw new InvalidCastException("Cannot convert Number to object.");

            case JsonValueTypes.Array:
                ReadArray(valueWriter.As <int>());
                return;

            case JsonValueTypes.True:
            case JsonValueTypes.False:
                throw new InvalidCastException("Cannot convert Boolean to object.");

            case JsonValueTypes.Null:
                /* 空对象直接返回 */
                index += 4;
                return;

            case JsonValueTypes.Undefined:
                index += 9;
                return;
            }

            var haveRef = false;

            while (index < length)
            {
                switch (chars[index])
                {
                case ' ':
                case '\n':
                case '\r':
                case '\t':
                    ++index;

                    continue;

                case '{':

                    valueWriter.Initialize();

                    goto case ',';

                case '}':
EndCase:

                    ++index;

                    goto ReturnValue;

                case ',':

Loop:

                    ++index;

                    if (index >= length)
                    {
                        throw GetException();
                    }

                    char c = chars[index];

                    string name;

                    int flag;

                    switch (c)
                    {
                    case ' ':
                    case '\n':
                    case '\r':
                    case '\t':
                        goto Loop;

                    case '}':
                        goto EndCase;

                    case '"':
                    case '\'':
                        name = InternalReadString();

                        flag = StringHelper.IndexOf(chars, ':', index, length);

                        break;

                    default:
                        flag = StringHelper.IndexOf(chars, ':', index, length);

                        name = StringHelper.Trim(chars, index, flag);

                        break;
                    }

                    if (flag == -1)
                    {
                        goto Exception;
                    }

                    index = flag + 1;

                    while (index < length)
                    {
                        switch (chars[index])
                        {
                        case ' ':
                        case '\n':
                        case '\r':
                        case '\t':
                            ++index;
                            continue;

                        default:
                            goto ReadValue;
                        }
                    }

                    goto Exception;

ReadValue:

                    if (TryReadRefReferenceTarget())
                    {
                        valueWriter.OnWriteValue(name, RWHelper.DefaultValueReader);

                        references.AddLast(new ReferenceInfo(referenceTarget, new SourcePathInfo(name, null, valueWriter)));

                        if (valueWriter is IDataReader reader && reader.ReferenceToken == null)
                        {
                            updateBase = true;
                        }

                        haveRef = true;
                    }
                    else
                    {
                        valueWriter.OnWriteValue(name, this);

                        if (updateBase)
                        {
                            var last = references.Last.Value;

                            last.source = new SourcePathInfo(name, last.source, valueWriter);

                            updateBase = false;

                            haveRef = true;
                        }
                    }

                    continue;

                default:
                    goto Exception;
                }
            }


Exception:
            throw GetException();

ReturnValue:

            if (haveRef && valueWriter is IDataReader dataReader && dataReader.ReferenceToken == null)
            {
                writer = valueWriter;

                updateBase = true;
            }

            return;
        }
Ejemplo n.º 15
0
        public void ReadObject(IDataWriter <string> valueWriter)
        {
            switch (GetValueType())
            {
            case JsonValueTypes.String:
                throw new InvalidCastException("Cannot convert String to object.");

            case JsonValueTypes.Number:
                throw new InvalidCastException("Cannot convert Number to object.");

            case JsonValueTypes.Array:
                ReadArray(valueWriter.As <int>());
                return;

            case JsonValueTypes.True:
            case JsonValueTypes.False:
                throw new InvalidCastException("Cannot convert Boolean to object.");

            case JsonValueTypes.Null:
                /* 空对象直接返回 */
                index += 4;
                return;

            case JsonValueTypes.Undefined:
                index += 9;
                return;
            }

            while (index < length)
            {
                switch (chars[index])
                {
                case ' ':
                case '\n':
                case '\r':
                case '\t':
                    ++index;

                    continue;

                case '{':

                    valueWriter.Initialize();

                    goto case ',';

                case '}':
EndCase:

                    ++index;

                    goto ReturnValue;

                case ',':

Loop:

                    ++index;

                    if (index >= length)
                    {
                        throw GetException();
                    }

                    char c = chars[index];

                    string name;

                    int flag;

                    switch (c)
                    {
                    case ' ':
                    case '\n':
                    case '\r':
                    case '\t':
                        goto Loop;

                    case '}':
                        goto EndCase;

                    case '"':
                    case '\'':
                        name = InternalReadString();

                        flag = StringHelper.IndexOf(chars, ':', index, length);

                        break;

                    default:
                        flag = StringHelper.IndexOf(chars, ':', index, length);

                        name = StringHelper.Trim(chars, index, flag);

                        break;
                    }

                    if (flag == -1)
                    {
                        goto Exception;
                    }

                    index = flag + 1;

                    while (index < length)
                    {
                        switch (chars[index])
                        {
                        case ' ':
                        case '\n':
                        case '\r':
                        case '\t':
                            ++index;
                            continue;

                        default:
                            goto ReadValue;
                        }
                    }

                    goto Exception;

ReadValue:

                    valueWriter.OnWriteValue(name, this);

                    continue;

                default:
                    goto Exception;
                }
            }


Exception:
            throw GetException();

ReturnValue:

            return;
        }
Ejemplo n.º 16
0
 /// <summary>
 /// 从值读取器中读取一个值设置到原始写入器的指定键的值中。
 /// </summary>
 /// <param name="key">指定键</param>
 /// <param name="valueReader">值读取器</param>
 public void OnWriteValue(TKey key, IValueReader valueReader)
 {
     DataWriter.OnWriteValue(key, valueReader);
 }
Ejemplo n.º 17
0
 /// <summary>
 /// 从值读取器中读取一个值设置到指定键的值中。
 /// </summary>
 /// <param name="key">指定键</param>
 /// <param name="valueReader">值读取器</param>
 public void OnWriteValue(TOut key, IValueReader valueReader)
 {
     dataWriter.OnWriteValue(XConvert <TIn> .Convert(key), valueReader);
 }
Ejemplo n.º 18
0
 public void OnWriteValue(Key key, IValueReader valueReader) => dataWriter.OnWriteValue(key, valueReader);
Ejemplo n.º 19
0
        public void ReadArray(IDataWriter <int> valueWriter)
        {
            switch (GetValueType())
            {
            case JsonValueTypes.String:
                throw new InvalidCastException("Cannot convert String to array.");

            case JsonValueTypes.Number:
                throw new InvalidCastException("Cannot convert Number to array.");

            case JsonValueTypes.Object:
                ReadObject(valueWriter.As <string>());
                return;

            case JsonValueTypes.True:
                throw new InvalidCastException("Cannot convert Boolean to array.");

            case JsonValueTypes.Null:
                /* 空对象直接返回 */
                this.index += 4;
                return;

            case JsonValueTypes.Undefined:
                this.index += 9;
                return;
            }

            int index = 0;

            while (this.index < length)
            {
                switch (chars[this.index])
                {
                case ' ':
                case '\n':
                case '\r':
                case '\t':

                    ++this.index;

                    continue;

                case '[':

                    valueWriter.Initialize();

                    goto case ',';

                case ']':
EndCase:

                    ++this.index;

                    goto ReturnValue;

                case ',':

                    ++this.index;

                    while (this.index < length)
                    {
                        switch (chars[this.index])
                        {
                        case ' ':
                        case '\n':
                        case '\r':
                        case '\t':
                            ++this.index;
                            continue;

                        case ']':
                            goto EndCase;

                        default:
                            goto ReadValue;
                        }
                    }

                    goto Exception;

ReadValue:

                    valueWriter.OnWriteValue(index, this);

                    ++index;

                    continue;

                default:

                    goto Exception;
                }
            }

Exception:
            throw GetException();

ReturnValue:

            return;
        }
Ejemplo n.º 20
0
        public override void ReadObject(IDataWriter <string> dataWriter)
        {
            if (!IsObject)
            {
                NoObjectOrArray(dataWriter);

                return;
            }

            ++current;

            dataWriter.Initialize();

Loop:

            SkipWhiteSpace();

            if (current < end)
            {
                string name;

                switch (*current)
                {
                case '}':
                    goto Return;

                case '"':
                case '\'':
                    name = InternalReadString();
                    break;

                default:
                    name = InternalReadText();
                    break;
                }

                SkipWhiteSpace();

                if (current < end && *current == ':')
                {
                    ++current;

                    SkipWhiteSpace();

                    if (current < end)
                    {
                        dataWriter.OnWriteValue(name, this);

                        SkipWhiteSpace();

                        if (current < end)
                        {
                            switch (*current)
                            {
                            case '}':
                                goto Return;

                            case ',':
                                ++current;

                                goto Loop;
                            }
                        }
                    }
                }
            }

            throw GetException();

Return:

            ++current;
        }
Ejemplo n.º 21
0
        public override void ReadObject(IDataWriter <string> dataWriter)
        {
            if (GetValueType() != JsonValueTypes.Object)
            {
                NoObjectOrArray(dataWriter);

                return;
            }

            while (index < length)
            {
                switch (chars[index])
                {
                case ' ':
                case '\n':
                case '\r':
                case '\t':
                    ++index;

                    continue;

                case '{':

                    dataWriter.Initialize();

                    goto case ',';

                case '}':
EndCase:

                    ++index;

                    goto ReturnValue;

                case ',':

Loop:

                    ++index;

                    if (index >= length)
                    {
                        throw GetException();
                    }

                    char c = chars[index];

                    string name;

                    int flag;

                    switch (c)
                    {
                    case ' ':
                    case '\n':
                    case '\r':
                    case '\t':
                        goto Loop;

                    case '}':
                        goto EndCase;

                    case '"':
                    case '\'':
                        name = InternalReadString();

                        flag = StringHelper.IndexOf(chars, index, length, ':');

                        break;

                    default:
                        flag = StringHelper.IndexOf(chars, index, length, ':');

                        name = StringHelper.Trim(chars, index, flag);

                        break;
                    }

                    if (flag == -1)
                    {
                        goto Exception;
                    }

                    index = flag + 1;

                    while (index < length)
                    {
                        switch (chars[index])
                        {
                        case ' ':
                        case '\n':
                        case '\r':
                        case '\t':
                            ++index;
                            continue;

                        default:
                            goto ReadValue;
                        }
                    }

                    goto Exception;

ReadValue:

                    dataWriter.OnWriteValue(name, this);

                    continue;

                default:
                    goto Exception;
                }
            }


Exception:
            throw GetException();

ReturnValue:

            return;
        }
Ejemplo n.º 22
0
        public override void ReadObject(IDataWriter <string> dataWriter)
        {
            if (!IsObject)
            {
                NoObjectOrArray(dataWriter);

                return;
            }

            var haveRef = false;

            ++current;

            dataWriter.Initialize();

Loop:

            SkipWhiteSpace();

            if (current < end)
            {
                string name;

                switch (*current)
                {
                case '}':
                    goto Return;

                case '"':
                case '\'':
                    name = InternalReadString();
                    break;

                default:
                    name = InternalReadText();
                    break;
                }

                SkipWhiteSpace();

                if (current < end && *current == ':')
                {
                    ++current;

                    SkipWhiteSpace();

                    if (TryReadRefReferenceTarget())
                    {
                        dataWriter.OnWriteValue(name, RWHelper.DefaultValueReader);

                        references.AddLast(new ReferenceInfo(referenceTarget, new SourcePathInfo(name, null, dataWriter)));

                        if (dataWriter is IDataReader reader && reader.ReferenceToken == null)
                        {
                            updateBase = true;
                        }

                        haveRef = true;
                    }
                    else
                    {
                        dataWriter.OnWriteValue(name, this);

                        if (updateBase)
                        {
                            var last = references.Last.Value;

                            last.source = new SourcePathInfo(name, last.source, dataWriter);

                            updateBase = false;

                            haveRef = true;
                        }
                    }

                    SkipWhiteSpace();

                    if (current < end)
                    {
                        switch (*current)
                        {
                        case '}':
                            goto Return;

                        case ',':
                            ++current;

                            goto Loop;
                        }
                    }
                }
            }

            throw GetException();

Return:

            ++current;

            if (haveRef && dataWriter is IDataReader dataReader && dataReader.ReferenceToken == null)
            {
                writer = dataWriter;

                updateBase = true;
            }
        }
Ejemplo n.º 23
0
        public override void ReadArray(IDataWriter <int> dataWriter)
        {
            if (GetValueType() != JsonValueTypes.Array)
            {
                NoObjectOrArray(dataWriter);

                return;
            }

            var haveRef = false;

            int index = 0;

            while (this.index < length)
            {
                switch (chars[this.index])
                {
                case ' ':
                case '\n':
                case '\r':
                case '\t':

                    ++this.index;

                    continue;

                case '[':

                    dataWriter.Initialize();

                    goto case ',';

                case ']':
EndCase:

                    ++this.index;

                    goto ReturnValue;

                case ',':

                    ++this.index;

                    while (this.index < length)
                    {
                        switch (chars[this.index])
                        {
                        case ' ':
                        case '\n':
                        case '\r':
                        case '\t':
                            ++this.index;
                            continue;

                        case ']':
                            goto EndCase;

                        default:
                            goto ReadValue;
                        }
                    }

                    goto Exception;

ReadValue:

                    if (TryReadRefReferenceTarget())
                    {
                        dataWriter.OnWriteValue(index, RWHelper.DefaultValueReader);

                        references.AddLast(new ReferenceInfo(referenceTarget, new SourcePathInfo(index, null, dataWriter)));

                        if (dataWriter is IDataReader reader && reader.ReferenceToken == null)
                        {
                            updateBase = true;
                        }

                        haveRef = true;
                    }
                    else
                    {
                        dataWriter.OnWriteValue(index, this);

                        if (updateBase)
                        {
                            var last = references.Last.Value;

                            last.source = new SourcePathInfo(index, last.source, dataWriter);

                            updateBase = false;

                            haveRef = true;
                        }
                    }

                    ++index;

                    continue;

                default:

                    goto Exception;
                }
            }

Exception:
            throw GetException();

ReturnValue:

            if (haveRef && dataWriter is IDataReader dataReader && dataReader.ReferenceToken == null)
            {
                writer = dataWriter;

                updateBase = true;
            }

            return;
        }
Ejemplo n.º 24
0
        public override void ReadObject(IDataWriter <string> dataWriter)
        {
            if (GetValueType() != JsonValueTypes.Object)
            {
                NoObjectOrArray(dataWriter);

                return;
            }

            var haveRef = false;

            while (index < length)
            {
                switch (chars[index])
                {
                case ' ':
                case '\n':
                case '\r':
                case '\t':
                    ++index;

                    continue;

                case '{':

                    dataWriter.Initialize();

                    goto case ',';

                case '}':
EndCase:

                    ++index;

                    goto ReturnValue;

                case ',':

Loop:

                    ++index;

                    if (index >= length)
                    {
                        throw GetException();
                    }

                    char c = chars[index];

                    string name;

                    int flag;

                    switch (c)
                    {
                    case ' ':
                    case '\n':
                    case '\r':
                    case '\t':
                        goto Loop;

                    case '}':
                        goto EndCase;

                    case '"':
                    case '\'':
                        name = InternalReadString();

                        flag = StringHelper.IndexOf(chars, index, length, ':');

                        break;

                    default:
                        flag = StringHelper.IndexOf(chars, index, length, ':');

                        name = StringHelper.Trim(chars, index, flag);

                        break;
                    }

                    if (flag == -1)
                    {
                        goto Exception;
                    }

                    index = flag + 1;

                    while (index < length)
                    {
                        switch (chars[index])
                        {
                        case ' ':
                        case '\n':
                        case '\r':
                        case '\t':
                            ++index;
                            continue;

                        default:
                            goto ReadValue;
                        }
                    }

                    goto Exception;

ReadValue:

                    if (TryReadRefReferenceTarget())
                    {
                        dataWriter.OnWriteValue(name, RWHelper.DefaultValueReader);

                        references.AddLast(new ReferenceInfo(referenceTarget, new SourcePathInfo(name, null, dataWriter)));

                        if (dataWriter is IDataReader reader && reader.ReferenceToken == null)
                        {
                            updateBase = true;
                        }

                        haveRef = true;
                    }
                    else
                    {
                        dataWriter.OnWriteValue(name, this);

                        if (updateBase)
                        {
                            var last = references.Last.Value;

                            last.source = new SourcePathInfo(name, last.source, dataWriter);

                            updateBase = false;

                            haveRef = true;
                        }
                    }

                    continue;

                default:
                    goto Exception;
                }
            }


Exception:
            throw GetException();

ReturnValue:

            if (haveRef && dataWriter is IDataReader dataReader && dataReader.ReferenceToken == null)
            {
                writer = dataWriter;

                updateBase = true;
            }

            return;
        }
Ejemplo n.º 25
0
        public override void ReadArray(IDataWriter <int> dataWriter)
        {
            if (!IsArray)
            {
                NoObjectOrArray(dataWriter);

                return;
            }

            var haveRef = false;
            var i       = 0;

            ++current;

            dataWriter.Initialize();

Loop:

            SkipWhiteSpace();

            if (current < end)
            {
                if (*current == ']')
                {
                    goto Return;
                }

                if (TryReadRefReferenceTarget())
                {
                    dataWriter.OnWriteValue(i, RWHelper.DefaultValueReader);

                    references.AddLast(new ReferenceInfo(referenceTarget, new SourcePathInfo(i, null, dataWriter)));

                    if (dataWriter is IDataReader reader && reader.ReferenceToken == null)
                    {
                        updateBase = true;
                    }

                    haveRef = true;
                }
                else
                {
                    dataWriter.OnWriteValue(i, this);

                    if (updateBase)
                    {
                        var last = references.Last.Value;

                        last.source = new SourcePathInfo(i, last.source, dataWriter);

                        updateBase = false;

                        haveRef = true;
                    }
                }

                SkipWhiteSpace();

                if (current < end)
                {
                    switch (*current)
                    {
                    case ']':
                        goto Return;

                    case ',':
                        ++current;

                        goto Loop;
                    }
                }
            }

            throw GetException();

Return:

            ++current;

            if (haveRef && dataWriter is IDataReader dataReader && dataReader.ReferenceToken == null)
            {
                writer = dataWriter;

                updateBase = true;
            }
        }
        public void Invoke <TElement>()
        {
            if (FastObjectRW <TElement> .IsFastObjectInterface)
            {
                var objectRW = FastObjectRW <TElement> .Create();

                var map = stackalloc int[objectRW.Count];

                Map = map;

                for (int i = 0; i < DbDataReader.FieldCount; i++)
                {
                    var index = objectRW.GetOrdinal(DbDataReader.GetName(i));

                    if (index >= 0)
                    {
                        map[index] = i + 1;
                    }
                }

                if (DataWriter.ContentType == typeof(TElement[]))
                {
                    ref var appendingInfo = ref GenericAppendingInfo <TElement> .ArrayAppendingInfo;

                    var elements = new TElement[appendingInfo.MostClosestMeanCommonlyUsedLength];

                    int offset = 0;

                    while (DbDataReader.Read())
                    {
                        if (offset >= elements.Length)
                        {
                            Array.Resize(ref elements, offset * 2 + 1);
                        }

                        objectRW.Initialize();

                        objectRW.OnWriteAll(this);

                        elements[offset] = objectRW.content;

                        ++offset;
                    }

                    if (elements.Length != offset)
                    {
                        Array.Resize(ref elements, offset);
                    }

                    appendingInfo.AddUsedLength(offset);

                    DataWriter.Content = elements;

                    Result = true;
                }
                else
                {
                    ref var appendingInfo = ref GenericAppendingInfo <TElement> .OtherAppendingInfo;

                    var copyer = new ValueCopyer();

                    DataWriter.Initialize(appendingInfo.MostClosestMeanCommonlyUsedLength);

                    int offset = 0;

                    while (DbDataReader.Read())
                    {
                        objectRW.Initialize();

                        objectRW.OnWriteAll(this);

                        copyer.DirectWrite(objectRW.content);

                        DataWriter.OnWriteValue(offset, copyer);

                        ++offset;
                    }

                    appendingInfo.AddUsedLength(offset);

                    Result = true;
                }
Ejemplo n.º 27
0
 /// <summary>
 /// 写入一个数组结构数据。
 /// </summary>
 /// <param name="dataReader">数据读取器</param>
 public void WriteArray(IDataReader <int> dataReader)
 {
     valueCopyer.WriteArray(dataReader);
     dataWriter.OnWriteValue(key, valueCopyer);
 }
Ejemplo n.º 28
0
        public override void ReadArray(IDataWriter <int> dataWriter)
        {
            if (GetValueType() != JsonValueTypes.Array)
            {
                NoObjectOrArray(dataWriter);

                return;
            }

            int index = 0;

            while (this.index < length)
            {
                switch (chars[this.index])
                {
                case ' ':
                case '\n':
                case '\r':
                case '\t':

                    ++this.index;

                    continue;

                case '[':

                    dataWriter.Initialize();

                    goto case ',';

                case ']':
EndCase:

                    ++this.index;

                    goto ReturnValue;

                case ',':

                    ++this.index;

                    while (this.index < length)
                    {
                        switch (chars[this.index])
                        {
                        case ' ':
                        case '\n':
                        case '\r':
                        case '\t':
                            ++this.index;
                            continue;

                        case ']':
                            goto EndCase;

                        default:
                            goto ReadValue;
                        }
                    }

                    goto Exception;

ReadValue:

                    dataWriter.OnWriteValue(index, this);

                    ++index;

                    continue;

                default:

                    goto Exception;
                }
            }

Exception:
            throw GetException();

ReturnValue:

            return;
        }
Ejemplo n.º 29
0
 public void OnWriteValue(TIn key, IValueReader valueReader) => dataWriter.OnWriteValue(XConvert <TOut> .Convert(key), valueReader);
Ejemplo n.º 30
0
        void IValueReader.ReadArray(IDataWriter <int> valueWriter)
        {
            switch (GetValueType())
            {
            case JsonValueTypes.String:
                throw new InvalidCastException("Cannot convert String to array.");

            case JsonValueTypes.Number:
                throw new InvalidCastException("Cannot convert Number to array.");

            case JsonValueTypes.Object:
                ReadObject(valueWriter.As <string>());
                return;

            case JsonValueTypes.True:
                throw new InvalidCastException("Cannot convert Boolean to array.");

            case JsonValueTypes.Null:
                /* 空对象直接返回 */
                this.index += 4;
                return;

            case JsonValueTypes.Undefined:
                this.index += 9;
                return;
            }

            var haveRef = false;

            int index = 0;

            while (this.index < length)
            {
                switch (chars[this.index])
                {
                case ' ':
                case '\n':
                case '\r':
                case '\t':

                    ++this.index;

                    continue;

                case '[':

                    valueWriter.Initialize();

                    goto case ',';

                case ']':
EndCase:

                    ++this.index;

                    goto ReturnValue;

                case ',':

                    ++this.index;

                    while (this.index < length)
                    {
                        switch (chars[this.index])
                        {
                        case ' ':
                        case '\n':
                        case '\r':
                        case '\t':
                            ++this.index;
                            continue;

                        case ']':
                            goto EndCase;

                        default:
                            goto ReadValue;
                        }
                    }

                    goto Exception;

ReadValue:

                    if (TryReadRefReferenceTarget())
                    {
                        valueWriter.OnWriteValue(index, RWHelper.DefaultValueReader);

                        references.AddLast(new ReferenceInfo(referenceTarget, new SourcePathInfo(index, null, valueWriter)));

                        if (valueWriter is IDataReader reader && reader.ReferenceToken == null)
                        {
                            updateBase = true;
                        }

                        haveRef = true;
                    }
                    else
                    {
                        valueWriter.OnWriteValue(index, this);

                        if (updateBase)
                        {
                            var last = references.Last.Value;

                            last.source = new SourcePathInfo(index, last.source, valueWriter);

                            updateBase = false;

                            haveRef = true;
                        }
                    }

                    ++index;

                    continue;

                default:

                    goto Exception;
                }
            }

Exception:
            throw GetException();

ReturnValue:

            if (haveRef && valueWriter is IDataReader dataReader && dataReader.ReferenceToken == null)
            {
                writer = valueWriter;

                updateBase = true;
            }

            return;
        }