internal void UnpackToCore(Unpacker unpacker, object collection, int itemsCount) { for (var i = 0; i < itemsCount; i++) { if (!unpacker.Read()) { SerializationExceptions.ThrowMissingItem(i, unpacker); } object item; if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader) { item = this._itemSerializer.UnpackFrom(unpacker); } else { using (var subtreeUnpacker = unpacker.ReadSubtree()) { item = this._itemSerializer.UnpackFrom(subtreeUnpacker); } } this.AddItem(collection, item); } }
protected internal override Vector2 UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector2), 2); } var length = unpacker.LastReadData.AsInt64(); if (length != 2) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector2), 2); } float x; if (!unpacker.ReadSingle(out x)) { SerializationExceptions.ThrowMissingItem(0, unpacker); } float y; if (!unpacker.ReadSingle(out y)) { SerializationExceptions.ThrowMissingItem(1, unpacker); } return(new Vector2(x, y)); }
internal async Task <TCollection> InternalUnpackToAsyncCore(Unpacker unpacker, TCollection collection, int itemsCount, CancellationToken cancellationToken) { for (var i = 0; i < itemsCount; i++) { if (!unpacker.Read()) { SerializationExceptions.ThrowMissingItem(i, unpacker); } object item; if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader) { item = await this._itemSerializer.UnpackFromAsync(unpacker, cancellationToken).ConfigureAwait(false); } else { using (var subtreeUnpacker = unpacker.ReadSubtree()) { item = await this._itemSerializer.UnpackFromAsync(subtreeUnpacker, cancellationToken).ConfigureAwait(false); } } this.AddItem(collection, item); } return(collection); }
protected internal override async Task <T> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowIsNotArrayHeader(unpacker); } var itemsCount = UnpackHelpers.GetItemsCount(unpacker); if (itemsCount != this._itemSerializers.Count) { SerializationExceptions.ThrowTupleCardinarityIsNotMatch(this._itemSerializers.Count, itemsCount, unpacker); } var unpackedItems = new List <object>(this._itemSerializers.Count); for (var i = 0; i < this._itemSerializers.Count; i++) { if (!await unpacker.ReadAsync(cancellationToken).ConfigureAwait(false)) { SerializationExceptions.ThrowMissingItem(i, unpacker); } unpackedItems.Add(await this._itemSerializers[i].UnpackFromAsync(unpacker, cancellationToken).ConfigureAwait(false)); } return(this.CreateTuple(unpackedItems)); }
protected internal override T UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowIsNotArrayHeader(unpacker); } var itemsCount = UnpackHelpers.GetItemsCount(unpacker); if (itemsCount != this._itemSerializers.Count) { SerializationExceptions.ThrowTupleCardinarityIsNotMatch(this._itemSerializers.Count, itemsCount, unpacker); } var unpackedItems = new List <object>(this._itemSerializers.Count); for (var i = 0; i < this._itemSerializers.Count; i++) { if (!unpacker.Read()) { SerializationExceptions.ThrowMissingItem(i, unpacker); } unpackedItems.Add(this._itemSerializers[i].UnpackFrom(unpacker)); } return(this.CreateTuple(unpackedItems)); }
protected internal override async Task UnpackToAsyncCore(Unpacker unpacker, Queue <TItem> collection, CancellationToken cancellationToken) { var itemsCount = UnpackHelpers.GetItemsCount(unpacker); for (int i = 0; i < itemsCount; i++) { if (!await unpacker.ReadAsync(cancellationToken).ConfigureAwait(false)) { SerializationExceptions.ThrowMissingItem(i, unpacker); } TItem item; if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader) { item = await this._itemSerializer.UnpackFromAsync(unpacker, cancellationToken).ConfigureAwait(false); } else { using (Unpacker subtreeUnpacker = unpacker.ReadSubtree()) { item = await this._itemSerializer.UnpackFromAsync(subtreeUnpacker, cancellationToken).ConfigureAwait(false); } } collection.Enqueue(item); } }
protected internal override void UnpackToCore(Unpacker unpacker, Queue <TItem> collection) { var itemsCount = UnpackHelpers.GetItemsCount(unpacker); for (int i = 0; i < itemsCount; i++) { if (!unpacker.Read()) { SerializationExceptions.ThrowMissingItem(i, unpacker); } TItem item; if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader) { item = this._itemSerializer.UnpackFrom(unpacker); } else { using (Unpacker subtreeUnpacker = unpacker.ReadSubtree()) { item = this._itemSerializer.UnpackFrom(subtreeUnpacker); } } collection.Enqueue(item); } }
private void UnpackToCore(Unpacker unpacker, IList collection, int count) #endif // !UNITY { for (int i = 0; i < count; i++) { if (!unpacker.Read()) { SerializationExceptions.ThrowMissingItem(i, unpacker); } #if !UNITY T item; #else object item; #endif // !UNITY if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader) { item = this._itemSerializer.UnpackFrom(unpacker); } else { using (var subtreeUnpacker = unpacker.ReadSubtree()) { item = this._itemSerializer.UnpackFrom(subtreeUnpacker); } } collection[i] = item; } }
protected internal override async Task <Vector2> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector2), 2); } var length = unpacker.LastReadData.AsInt64(); if (length != 2) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector2), 2); } var x = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!x.Success) { SerializationExceptions.ThrowMissingItem(0, unpacker); } var y = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!y.Success) { SerializationExceptions.ThrowMissingItem(1, unpacker); } return(new Vector2(x.Value, y.Value)); }
private async Task UnpackToAsyncCore(Unpacker unpacker, T[] collection, int count, CancellationToken cancellationToken) { for (int i = 0; i < count; i++) { if (!await unpacker.ReadAsync(cancellationToken).ConfigureAwait(false)) { SerializationExceptions.ThrowMissingItem(i, unpacker); } T item; if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader) { item = await this._itemSerializer.UnpackFromAsync(unpacker, cancellationToken).ConfigureAwait(false); } else { using (var subtreeUnpacker = unpacker.ReadSubtree()) { item = await this._itemSerializer.UnpackFromAsync(subtreeUnpacker, cancellationToken).ConfigureAwait(false); } } collection[i] = item; } }
protected internal override Matrix3x2 UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6); } var length = unpacker.LastReadData.AsInt64(); if (length != 6) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6); } float m11; if (!unpacker.ReadSingle(out m11)) { SerializationExceptions.ThrowMissingItem(0, unpacker); } float m12; if (!unpacker.ReadSingle(out m12)) { SerializationExceptions.ThrowMissingItem(1, unpacker); } float m21; if (!unpacker.ReadSingle(out m21)) { SerializationExceptions.ThrowMissingItem(2, unpacker); } float m22; if (!unpacker.ReadSingle(out m22)) { SerializationExceptions.ThrowMissingItem(3, unpacker); } float m31; if (!unpacker.ReadSingle(out m31)) { SerializationExceptions.ThrowMissingItem(4, unpacker); } float m32; if (!unpacker.ReadSingle(out m32)) { SerializationExceptions.ThrowMissingItem(5, unpacker); } return(new Matrix3x2(m11, m12, m21, m22, m31, m32)); }
protected internal override async Task <Matrix3x2> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6); } var length = unpacker.LastReadData.AsInt64(); if (length != 6) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6); } var m11 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m11.Success) { SerializationExceptions.ThrowMissingItem(0, unpacker); } var m12 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m12.Success) { SerializationExceptions.ThrowMissingItem(1, unpacker); } var m21 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m21.Success) { SerializationExceptions.ThrowMissingItem(2, unpacker); } var m22 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m22.Success) { SerializationExceptions.ThrowMissingItem(3, unpacker); } var m31 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m31.Success) { SerializationExceptions.ThrowMissingItem(4, unpacker); } var m32 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m32.Success) { SerializationExceptions.ThrowMissingItem(5, unpacker); } return(new Matrix3x2(m11.Value, m12.Value, m21.Value, m22.Value, m31.Value, m32.Value)); }
protected internal override async Task <Version> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Version), 4); } long length = unpacker.LastReadData.AsInt64(); if (length != 4) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Version), 4); } var major = await unpacker.ReadInt32Async(cancellationToken).ConfigureAwait(false); if (!major.Success) { SerializationExceptions.ThrowMissingItem(0, unpacker); } var minor = await unpacker.ReadInt32Async(cancellationToken).ConfigureAwait(false); if (!minor.Success) { SerializationExceptions.ThrowMissingItem(1, unpacker); } var build = await unpacker.ReadInt32Async(cancellationToken).ConfigureAwait(false); if (!build.Success) { SerializationExceptions.ThrowMissingItem(2, unpacker); } var revision = await unpacker.ReadInt32Async(cancellationToken).ConfigureAwait(false); if (!revision.Success) { SerializationExceptions.ThrowMissingItem(3, unpacker); } if (build.Value < 0 && revision.Value < 0) { return(new Version(major.Value, minor.Value)); } else if (revision.Value < 0) { return(new Version(major.Value, minor.Value, build.Value)); } return(new Version(major.Value, minor.Value, build.Value, revision.Value)); }
protected internal override void UnpackToCore(Unpacker unpacker, Queue collection) { var itemsCount = UnpackHelpers.GetItemsCount(unpacker); for (int i = 0; i < itemsCount; i++) { if (!unpacker.Read()) { SerializationExceptions.ThrowMissingItem(i, unpacker); } collection.Enqueue(unpacker.LastReadData); } }
protected internal override Quaternion UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Quaternion), 4); } var length = UnpackHelpers.GetItemsCount(unpacker); if (length != 4) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Quaternion), 4); } float x; if (!unpacker.ReadSingle(out x)) { SerializationExceptions.ThrowMissingItem(0, unpacker); } float y; if (!unpacker.ReadSingle(out y)) { SerializationExceptions.ThrowMissingItem(1, unpacker); } float z; if (!unpacker.ReadSingle(out z)) { SerializationExceptions.ThrowMissingItem(2, unpacker); } float w; if (!unpacker.ReadSingle(out w)) { SerializationExceptions.ThrowMissingItem(3, unpacker); } return(new Quaternion(x, y, z, w)); }
protected internal override async Task <Plane> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Plane), 4); } var length = unpacker.LastReadData.AsInt64(); if (length != 4) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Plane), 4); } var normal_X = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!normal_X.Success) { SerializationExceptions.ThrowMissingItem(0, unpacker); } var normal_Y = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!normal_Y.Success) { SerializationExceptions.ThrowMissingItem(1, unpacker); } var normal_Z = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!normal_Z.Success) { SerializationExceptions.ThrowMissingItem(2, unpacker); } var d = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!d.Success) { SerializationExceptions.ThrowMissingItem(3, unpacker); } return(new Plane(normal_X.Value, normal_Y.Value, normal_Z.Value, d.Value)); }
protected internal override Plane UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Plane), 4); } var length = UnpackHelpers.GetItemsCount(unpacker); if (length != 4) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Plane), 4); } float normal_X; if (!unpacker.ReadSingle(out normal_X)) { SerializationExceptions.ThrowMissingItem(0, unpacker); } float normal_Y; if (!unpacker.ReadSingle(out normal_Y)) { SerializationExceptions.ThrowMissingItem(1, unpacker); } float normal_Z; if (!unpacker.ReadSingle(out normal_Z)) { SerializationExceptions.ThrowMissingItem(2, unpacker); } float d; if (!unpacker.ReadSingle(out d)) { SerializationExceptions.ThrowMissingItem(3, unpacker); } return(new Plane(normal_X, normal_Y, normal_Z, d)); }
protected internal override async Task UnpackToAsyncCore(Unpacker unpacker, Queue collection, CancellationToken cancellationToken) { var itemsCount = UnpackHelpers.GetItemsCount(unpacker); for (int i = 0; i < itemsCount; i++) { if (!await unpacker.ReadAsync(cancellationToken).ConfigureAwait(false)) { SerializationExceptions.ThrowMissingItem(i, unpacker); } collection.Enqueue(unpacker.LastReadData); } }
public static ArraySegment <T> UnpackGenericArraySegmentFrom <T>(Unpacker unpacker, MessagePackSerializer <T> itemSerializer) { T[] array = new T[unpacker.ItemsCount]; for (int i = 0; i < array.Length; i++) { if (!unpacker.Read()) { SerializationExceptions.ThrowMissingItem(i, unpacker); } array[i] = itemSerializer.UnpackFrom(unpacker); } return(new ArraySegment <T>(array)); }
public static async Task <ArraySegment <T> > UnpackGenericArraySegmentFromAsync <T>(Unpacker unpacker, MessagePackSerializer <T> itemSerializer, CancellationToken cancellationToken) { T[] array = new T[unpacker.ItemsCount]; for (int i = 0; i < array.Length; i++) { if (!await unpacker.ReadAsync(cancellationToken).ConfigureAwait(false)) { SerializationExceptions.ThrowMissingItem(i, unpacker); } array[i] = await itemSerializer.UnpackFromAsyncCore(unpacker, cancellationToken).ConfigureAwait(false); } return(new ArraySegment <T>(array)); }
protected internal override Version UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Version), 4); } long length = UnpackHelpers.GetItemsCount(unpacker); if (length != 4) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Version), 4); } int major, minor, build, revision; if (!unpacker.ReadInt32(out major)) { SerializationExceptions.ThrowMissingItem(0, unpacker); } if (!unpacker.ReadInt32(out minor)) { SerializationExceptions.ThrowMissingItem(1, unpacker); } if (!unpacker.ReadInt32(out build)) { SerializationExceptions.ThrowMissingItem(2, unpacker); } if (!unpacker.ReadInt32(out revision)) { SerializationExceptions.ThrowMissingItem(3, unpacker); } if (build < 0 && revision < 0) { return(new Version(major, minor)); } else if (revision < 0) { return(new Version(major, minor, build)); } return(new Version(major, minor, build, revision)); }
private async Task<TDictionary> UnpackToAsyncCore( Unpacker unpacker, TDictionary collection, int itemsCount, CancellationToken cancellationToken ) { for ( int i = 0; i < itemsCount; i++ ) { if ( !unpacker.Read() ) { SerializationExceptions.ThrowMissingKey( i, unpacker ); } TKey key; if ( !unpacker.IsArrayHeader && !unpacker.IsMapHeader ) { key = await this._keySerializer.UnpackFromAsync( unpacker, cancellationToken ).ConfigureAwait( false ); } else { using ( var subtreeUnpacker = unpacker.ReadSubtree() ) { key = await this._keySerializer.UnpackFromAsync( subtreeUnpacker, cancellationToken ).ConfigureAwait( false ); } } if ( !unpacker.Read() ) { SerializationExceptions.ThrowMissingItem( i, unpacker ); } TValue value; if ( !unpacker.IsArrayHeader && !unpacker.IsMapHeader ) { value = await this._valueSerializer.UnpackFromAsync( unpacker, cancellationToken ).ConfigureAwait( false ); } else { using ( var subtreeUnpacker = unpacker.ReadSubtree() ) { value = await this._valueSerializer.UnpackFromAsync( subtreeUnpacker, cancellationToken ).ConfigureAwait( false ); } } this.AddItem( collection, key, value ); } return collection; }
private void UnpackToCore( Unpacker unpacker, TDictionary collection, int itemsCount ) { for ( int i = 0; i < itemsCount; i++ ) { if ( !unpacker.Read() ) { SerializationExceptions.ThrowMissingKey( i, unpacker ); } TKey key; if ( !unpacker.IsArrayHeader && !unpacker.IsMapHeader ) { key = this._keySerializer.UnpackFrom( unpacker ); } else { using ( var subtreeUnpacker = unpacker.ReadSubtree() ) { key = this._keySerializer.UnpackFrom( subtreeUnpacker ); } } if ( !unpacker.Read() ) { SerializationExceptions.ThrowMissingItem( i, unpacker ); } TValue value; if ( !unpacker.IsArrayHeader && !unpacker.IsMapHeader ) { value = this._valueSerializer.UnpackFrom( unpacker ); } else { using ( var subtreeUnpacker = unpacker.ReadSubtree() ) { value = this._valueSerializer.UnpackFrom( subtreeUnpacker ); } } this.AddItem( collection, key, value ); } }
private void UnpackToCore(Unpacker unpacker, object collection, int itemsCount) { for (int i = 0; i < itemsCount; i++) { if (!unpacker.Read()) { SerializationExceptions.ThrowMissingItem(i, unpacker); } object key; if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader) { key = this._keySerializer.UnpackFrom(unpacker); } else { using (var subtreeUnpacker = unpacker.ReadSubtree()) { key = this._keySerializer.UnpackFrom(subtreeUnpacker); } } if (!unpacker.Read()) { SerializationExceptions.ThrowMissingItem(i, (key ?? String.Empty).ToString(), unpacker); } object value; if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader) { value = this._valueSerializer.UnpackFrom(unpacker); } else { using (var subtreeUnpacker = unpacker.ReadSubtree()) { value = this._valueSerializer.UnpackFrom(subtreeUnpacker); } } this._add.InvokePreservingExceptionType(collection, key, value); } }
protected internal override Vector3 UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector3), 3); } var length = UnpackHelpers.GetItemsCount(unpacker); if (length != 3) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector3), 3); } float x; if (!unpacker.ReadSingle(out x)) { SerializationExceptions.ThrowMissingItem(0, unpacker); } float y; if (!unpacker.ReadSingle(out y)) { SerializationExceptions.ThrowMissingItem(1, unpacker); } float z; if (!unpacker.ReadSingle(out z)) { SerializationExceptions.ThrowMissingItem(2, unpacker); } return(new Vector3(x, y, z)); }
private async Task <object> UnpackMemberValueAsync(object objectGraph, Unpacker unpacker, int itemsCount, int unpacked, int index, int unpackerOffset, CancellationToken cancellationToken) { object nullable = null; var setter = index < this._setters.Length ? this._setters[index] : null; if (unpacked < itemsCount) { if (!unpacker.Read()) { SerializationExceptions.ThrowMissingItem(unpackerOffset, unpacker); } if (!unpacker.LastReadData.IsNil) { if (setter != null || this._constructorParameters != null) { nullable = await this.UnpackSingleValueAsync(unpacker, index, cancellationToken).ConfigureAwait(false); } else if (this._getters[index] != null) // null getter supposes undeclared member (should be treated as nil) { await this.UnpackAndAddCollectionItemAsync(objectGraph, unpacker, index, cancellationToken).ConfigureAwait(false); } } } if (this._constructorParameters != null) { #if DEBUG Contract.Assert(objectGraph is object[], "objectGraph is object[]"); #endif // DEBUG int argumentIndex; if (this._constructorArgumentIndexes.TryGetValue(index, out argumentIndex)) { if (nullable == null) { ReflectionNilImplicationHandler.Instance.OnUnpacked( new ReflectionSerializerNilImplicationHandlerOnUnpackedParameter( this._memberInfos[index].GetMemberValueType(), // ReSharper disable once PossibleNullReferenceException value => (objectGraph as object[])[argumentIndex] = nullable, this._contracts[index].Name, this._memberInfos[index].DeclaringType ), this._contracts[index].NilImplication )(null); } else { (objectGraph as object[])[argumentIndex] = nullable; } } } else if (setter != null) { if (nullable == null) { ReflectionNilImplicationHandler.Instance.OnUnpacked( new ReflectionSerializerNilImplicationHandlerOnUnpackedParameter( this._memberInfos[index].GetMemberValueType(), value => setter(objectGraph, nullable), this._contracts[index].Name, this._memberInfos[index].DeclaringType ), this._contracts[index].NilImplication )(null); } else { setter(objectGraph, nullable); } } return(objectGraph); } // UnpackMemberValueAsync
} // UnpackAndAddCollectionItem #if FEATURE_TAP protected internal override async Task <T> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken) { object result = this._constructorParameters == null ? ReflectionExtensions.CreateInstancePreservingExceptionType(typeof(T)) : this._constructorParameters.Select(p => p.GetHasDefaultValue() ? p.DefaultValue : p.ParameterType.GetIsValueType() ? ReflectionExtensions.CreateInstancePreservingExceptionType(p.ParameterType) : null ).ToArray(); var unpacked = 0; var asAsyncUnpackable = result as IAsyncUnpackable; if (asAsyncUnpackable != null) { await asAsyncUnpackable.UnpackFromMessageAsync(unpacker, cancellationToken).ConfigureAwait(false); return(( T )result); } var asUnpackable = result as IUnpackable; if (asUnpackable != null) { await Task.Run(() => asUnpackable.UnpackFromMessage(unpacker), cancellationToken).ConfigureAwait(false); return(( T )result); } if (unpacker.IsArrayHeader) { var itemsCount = UnpackHelpers.GetItemsCount(unpacker); for (int i = 0; i < itemsCount; i++) { result = await this.UnpackMemberValueAsync(result, unpacker, itemsCount, unpacked, i, i, cancellationToken).ConfigureAwait(false); unpacked++; } } else { #if DEBUG Contract.Assert(unpacker.IsMapHeader, "unpacker.IsMapHeader"); #endif // DEBUG var itemsCount = UnpackHelpers.GetItemsCount(unpacker); for (int i = 0; i < itemsCount; i++) { var name = await unpacker.ReadStringAsync(cancellationToken).ConfigureAwait(false); if (!name.Success) { SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker); } if (name.Value == null) { // missing member, drain the value and discard it. if (!unpacker.Read() && i < itemsCount - 1) { SerializationExceptions.ThrowMissingKey(i + 1, unpacker); } continue; } int index; if (!this._memberIndexes.TryGetValue(name.Value, out index)) { // key does not exist in the object, skip the associated value if (unpacker.Skip() == null) { SerializationExceptions.ThrowMissingItem(i, unpacker); } continue; } result = await this.UnpackMemberValueAsync(result, unpacker, itemsCount, unpacked, index, i, cancellationToken).ConfigureAwait(false); unpacked++; } } if (this._constructorParameters == null) { return(( T )result); } else { return(ReflectionExtensions.CreateInstancePreservingExceptionType <T>(typeof(T), result as object[])); } }
protected internal override Matrix4x4 UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix4x4), 16); } var length = unpacker.LastReadData.AsInt64(); if (length != 16) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix4x4), 16); } float m11; if (!unpacker.ReadSingle(out m11)) { SerializationExceptions.ThrowMissingItem(0, unpacker); } float m12; if (!unpacker.ReadSingle(out m12)) { SerializationExceptions.ThrowMissingItem(1, unpacker); } float m13; if (!unpacker.ReadSingle(out m13)) { SerializationExceptions.ThrowMissingItem(2, unpacker); } float m14; if (!unpacker.ReadSingle(out m14)) { SerializationExceptions.ThrowMissingItem(3, unpacker); } float m21; if (!unpacker.ReadSingle(out m21)) { SerializationExceptions.ThrowMissingItem(4, unpacker); } float m22; if (!unpacker.ReadSingle(out m22)) { SerializationExceptions.ThrowMissingItem(5, unpacker); } float m23; if (!unpacker.ReadSingle(out m23)) { SerializationExceptions.ThrowMissingItem(6, unpacker); } float m24; if (!unpacker.ReadSingle(out m24)) { SerializationExceptions.ThrowMissingItem(7, unpacker); } float m31; if (!unpacker.ReadSingle(out m31)) { SerializationExceptions.ThrowMissingItem(8, unpacker); } float m32; if (!unpacker.ReadSingle(out m32)) { SerializationExceptions.ThrowMissingItem(9, unpacker); } float m33; if (!unpacker.ReadSingle(out m33)) { SerializationExceptions.ThrowMissingItem(10, unpacker); } float m34; if (!unpacker.ReadSingle(out m34)) { SerializationExceptions.ThrowMissingItem(11, unpacker); } float m41; if (!unpacker.ReadSingle(out m41)) { SerializationExceptions.ThrowMissingItem(12, unpacker); } float m42; if (!unpacker.ReadSingle(out m42)) { SerializationExceptions.ThrowMissingItem(13, unpacker); } float m43; if (!unpacker.ReadSingle(out m43)) { SerializationExceptions.ThrowMissingItem(14, unpacker); } float m44; if (!unpacker.ReadSingle(out m44)) { SerializationExceptions.ThrowMissingItem(15, unpacker); } return(new Matrix4x4(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44)); }
protected internal override async Task <Matrix4x4> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix4x4), 16); } var length = unpacker.LastReadData.AsInt64(); if (length != 16) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix4x4), 16); } var m11 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m11.Success) { SerializationExceptions.ThrowMissingItem(0, unpacker); } var m12 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m12.Success) { SerializationExceptions.ThrowMissingItem(1, unpacker); } var m13 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m13.Success) { SerializationExceptions.ThrowMissingItem(2, unpacker); } var m14 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m14.Success) { SerializationExceptions.ThrowMissingItem(3, unpacker); } var m21 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m21.Success) { SerializationExceptions.ThrowMissingItem(4, unpacker); } var m22 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m22.Success) { SerializationExceptions.ThrowMissingItem(5, unpacker); } var m23 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m23.Success) { SerializationExceptions.ThrowMissingItem(6, unpacker); } var m24 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m24.Success) { SerializationExceptions.ThrowMissingItem(7, unpacker); } var m31 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m31.Success) { SerializationExceptions.ThrowMissingItem(8, unpacker); } var m32 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m32.Success) { SerializationExceptions.ThrowMissingItem(9, unpacker); } var m33 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m33.Success) { SerializationExceptions.ThrowMissingItem(10, unpacker); } var m34 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m34.Success) { SerializationExceptions.ThrowMissingItem(11, unpacker); } var m41 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m41.Success) { SerializationExceptions.ThrowMissingItem(12, unpacker); } var m42 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m42.Success) { SerializationExceptions.ThrowMissingItem(13, unpacker); } var m43 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m43.Success) { SerializationExceptions.ThrowMissingItem(14, unpacker); } var m44 = await unpacker.ReadSingleAsync(cancellationToken).ConfigureAwait(false); if (!m44.Success) { SerializationExceptions.ThrowMissingItem(15, unpacker); } return(new Matrix4x4(m11.Value, m12.Value, m13.Value, m14.Value, m21.Value, m22.Value, m23.Value, m24.Value, m31.Value, m32.Value, m33.Value, m34.Value, m41.Value, m42.Value, m43.Value, m44.Value)); }