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"); } }
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"); } }
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."); }
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."); }
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); } } }
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."); }
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; }
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()); } }
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); } } }
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); } } }
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); } } }
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 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; }
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; }
/// <summary> /// 初始化原始写入器。 /// </summary> public void Initialize() { DataWriter.Initialize(); }
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; }
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; }
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; }
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; }
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; }
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; }
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; }
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; } }
public void Initialize() => dataWriter.Initialize();
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; }