protected internal override Vector2 UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Vector2), 2); } var length = UnpackHelpers.GetItemsCount(unpacker); 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)); }
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); } }
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); } }
internal virtual Task <TCollection> InternalUnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken) { var itemsCount = UnpackHelpers.GetItemsCount(unpacker); var collection = this.CreateInstance(itemsCount); return(this.InternalUnpackToAsyncCore(unpacker, collection, itemsCount, cancellationToken)); }
protected internal override DateTimeOffset UnpackFromCore(Unpacker unpacker) { if (unpacker.IsArrayHeader) { if (UnpackHelpers.GetItemsCount(unpacker) != 2) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(DateTimeOffset), 2); } long ticks; if (!unpacker.ReadInt64(out ticks)) { SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker); } short offsetMinutes; if (!unpacker.ReadInt16(out offsetMinutes)) { SerializationExceptions.ThrowUnexpectedEndOfStream(unpacker); } return(new DateTimeOffset(DateTime.FromBinary(ticks), TimeSpan.FromMinutes(offsetMinutes))); } else { return(MessagePackConvert.ToDateTimeOffset(unpacker.LastReadData.AsInt64())); } }
protected internal override Matrix3x2 UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowInvalidArrayItemsCount(unpacker, typeof(Matrix3x2), 6); } var length = UnpackHelpers.GetItemsCount(unpacker); 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)); }
internal virtual object InternalUnpackFromCore(Unpacker unpacker) { var itemsCount = UnpackHelpers.GetItemsCount(unpacker); var collection = this.CreateInstance(itemsCount); this.UnpackToCore(unpacker, collection, itemsCount); return(collection); }
protected internal override void UnpackToCore(Unpacker unpacker, NameValueCollection collection) { if (!unpacker.IsMapHeader) { SerializationExceptions.ThrowIsNotMapHeader(unpacker); } UnpackToCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker)); }
protected internal override void UnpackToCore(Unpacker unpacker, Dictionary <TKey, TValue> collection) { if (!unpacker.IsMapHeader) { SerializationExceptions.ThrowIsNotMapHeader(unpacker); } this.UnpackToCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker)); }
protected internal override async Task <Stack> UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowIsNotArrayHeader(unpacker); } return(new Stack(await UnpackItemsInReverseOrderAsync(unpacker, UnpackHelpers.GetItemsCount(unpacker), cancellationToken).ConfigureAwait(false))); }
protected internal override void UnpackToCore(Unpacker unpacker, object collection) { if (!unpacker.IsMapHeader) { SerializationExceptions.ThrowIsNotArrayHeader(unpacker); } this.UnpackToCore(unpacker, collection as IDictionary, UnpackHelpers.GetItemsCount(unpacker)); }
protected internal override void UnpackToCore(Unpacker unpacker, List <T> collection) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } this.UnpackToCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker)); }
protected internal override Stack <TItem> UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } return(new Stack <TItem>(this.UnpackItemsInReverseOrder(unpacker, UnpackHelpers.GetItemsCount(unpacker)))); }
protected internal override Task UnpackToAsyncCore(Unpacker unpacker, Dictionary <TKey, TValue> collection, CancellationToken cancellationToken) { if (!unpacker.IsMapHeader) { SerializationExceptions.ThrowIsNotMapHeader(unpacker); } return(this.UnpackToAsyncCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker), cancellationToken)); }
protected internal override void UnpackToCore(Unpacker unpacker, List <MessagePackObject> collection) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowIsNotArrayHeader(unpacker); } UnpackToCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker)); }
protected internal override Task UnpackToAsyncCore(Unpacker unpacker, List <MessagePackObject> collection, CancellationToken cancellationToken) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowIsNotArrayHeader(unpacker); } return(UnpackToAsyncCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker), cancellationToken)); }
protected internal override async Task UnpackToAsyncCore(Unpacker unpacker, Stack collection, CancellationToken cancellationToken) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowIsNotArrayHeader(unpacker); } foreach (var item in await UnpackItemsInReverseOrderAsync(unpacker, UnpackHelpers.GetItemsCount(unpacker), cancellationToken).ConfigureAwait(false)) { collection.Push(item); } }
protected internal override object UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } var instance = Array.CreateInstance(this.Traits.ElementType, UnpackHelpers.GetItemsCount(unpacker)); this.UnpackToCore(unpacker, instance); return(instance); }
protected internal override T UnpackFromCore(Unpacker unpacker) { var result = Activator.CreateInstance <T>(); var unpacked = 0; var asUnpackable = result as IUnpackable; if (asUnpackable != null) { asUnpackable.UnpackFromMessage(unpacker); return(result); } if (unpacker.IsArrayHeader) { var itemsCount = UnpackHelpers.GetItemsCount(unpacker); for (int i = 0; i < itemsCount; i++) { result = this.UnpackMemberValue(result, unpacker, itemsCount, ref unpacked, i, i); } } else { #if DEBUG && !UNITY Contract.Assert(unpacker.IsMapHeader); #endif // DEBUG && !UNITY var itemsCount = UnpackHelpers.GetItemsCount(unpacker); for (int i = 0; i < itemsCount; i++) { string name; if (!unpacker.ReadString(out name)) { throw SerializationExceptions.NewUnexpectedEndOfStream(); } if (name == null) { // missing member, drain the value and discard it. if (!unpacker.Read()) { throw SerializationExceptions.NewMissingItem(i); } continue; } result = this.UnpackMemberValue(result, unpacker, itemsCount, ref unpacked, this._memberIndexes[name], i); } } return(result); }
protected internal override void UnpackToCore(Unpacker unpacker, Stack <TItem> collection) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } foreach (var item in this.UnpackItemsInReverseOrder(unpacker, UnpackHelpers.GetItemsCount(unpacker))) { collection.Push(item); } }
protected internal override Dictionary <TKey, TValue> UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsMapHeader) { SerializationExceptions.ThrowIsNotMapHeader(unpacker); } var count = UnpackHelpers.GetItemsCount(unpacker); var collection = new Dictionary <TKey, TValue>(count); this.UnpackToCore(unpacker, collection, count); return(collection); }
protected internal override MessagePackObjectDictionary UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsMapHeader) { throw SerializationExceptions.NewIsNotMapHeader(); } var count = UnpackHelpers.GetItemsCount(unpacker); var result = new MessagePackObjectDictionary(count); UnpackToCore(unpacker, count, result); return(result); }
protected internal override object UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } var itemsCount = UnpackHelpers.GetItemsCount(unpacker); var collection = this.CreateInstance(itemsCount); this.UnpackToCore(unpacker, collection, itemsCount); return(collection); }
protected internal override List <T> UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } var count = UnpackHelpers.GetItemsCount(unpacker); var collection = new List <T>(count); this.UnpackToCore(unpacker, collection, count); return(collection); }
protected internal override async Task <Queue <TItem> > UnpackFromAsyncCore(Unpacker unpacker, CancellationToken cancellationToken) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowIsNotArrayHeader(unpacker); } var queue = new Queue <TItem>(UnpackHelpers.GetItemsCount(unpacker)); await this.UnpackToAsyncCore(unpacker, queue, cancellationToken).ConfigureAwait(false); return(queue); }
protected internal override NameValueCollection UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsMapHeader) { SerializationExceptions.ThrowIsNotMapHeader(unpacker); } var count = UnpackHelpers.GetItemsCount(unpacker); var collection = new NameValueCollection(count); UnpackToCore(unpacker, collection, count); return(collection); }
protected internal override T[] UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } var count = UnpackHelpers.GetItemsCount(unpacker); var result = new T[count]; this.UnpackToCore(unpacker, result, count); return(result); }
protected internal override Queue <TItem> UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } var queue = new Queue <TItem>(UnpackHelpers.GetItemsCount(unpacker)); this.UnpackToCore(unpacker, queue); return(queue); }
protected internal override List <MessagePackObject> UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { SerializationExceptions.ThrowIsNotArrayHeader(unpacker); } var count = UnpackHelpers.GetItemsCount(unpacker); var collection = new List <MessagePackObject>(count); UnpackToCore(unpacker, collection, count); return(collection); }