protected override Quaternion UnpackFromCore(Unpacker unpacker) { //IL_008b: Unknown result type (might be due to invalid IL or missing references) if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } int itemsCount = UnpackHelpers.GetItemsCount(unpacker); if (itemsCount != 4) { throw SerializationExceptions.NewIsNotArrayHeader(); } if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } if (!unpacker.ReadSingle(out float result)) { throw SerializationExceptions.NewMissingItem(0); } if (!unpacker.ReadSingle(out float result2)) { throw SerializationExceptions.NewMissingItem(1); } if (!unpacker.ReadSingle(out float result3)) { throw SerializationExceptions.NewMissingItem(2); } if (!unpacker.ReadSingle(out float result4)) { throw SerializationExceptions.NewMissingItem(2); } return(new Quaternion(result, result2, result3, result4)); }
protected internal override T UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } var buffer = new TItem[UnpackHelpers.GetItemsCount(unpacker)]; using (var subTreeUnpacker = unpacker.ReadSubtree()) { // Reverse Order for (int i = buffer.Length - 1; i >= 0; i--) { if (!subTreeUnpacker.Read()) { throw SerializationExceptions.NewUnexpectedEndOfStream(); } buffer[i] = this._itemSerializer.UnpackFrom(subTreeUnpacker); } } return(factory(buffer)); }
protected internal override T UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } var itemsCount = UnpackHelpers.GetItemsCount(unpacker); if (itemsCount != this._itemSerializers.Count) { throw SerializationExceptions.NewTupleCardinarityIsNotMatch(this._itemSerializers.Count, itemsCount); } var unpackedItems = new List <object>(this._itemSerializers.Count); for (var i = 0; i < this._itemSerializers.Count; i++) { if (!unpacker.Read()) { throw SerializationExceptions.NewMissingItem(i); } unpackedItems.Add(this._itemSerializers[i].UnpackFrom(unpacker)); } return(this.CreateTuple(unpackedItems)); }
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 sealed override TList UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } return(this.InternalUnpackFromCore(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 sealed override void UnpackToCore(Unpacker unpacker, object collection) { if (!unpacker.IsMapHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } this.UnpackToCore(unpacker, collection as IDictionary, UnpackHelpers.GetItemsCount(unpacker)); }
protected internal override T UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } var instance = ( T )( object )Array.CreateInstance(this.Traits.ElementType, UnpackHelpers.GetItemsCount(unpacker)); this.UnpackToCore(unpacker, instance); return(instance); }
protected internal override object UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } var instance = this._createInstanceWithCapacity == null?this._createInstance() : this._createInstanceWithCapacity(UnpackHelpers.GetItemsCount(unpacker)); this.UnpackToCore(unpacker, instance); return(instance); }
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 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 <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 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 T UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } if (( int )unpacker.ItemsCount != this._itemSerializers.Length) { throw SerializationExceptions.NewTupleCardinarityIsNotMatch(this._itemSerializers.Length, ( int )unpacker.ItemsCount); } return(this._unpackFromCore(unpacker, this._itemSerializers)); }
protected internal override void UnpackToCore(Unpacker unpacker, object collection) #endif // !UNITY { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } #if !UNITY this.UnpackToCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker)); #else this.UnpackToCore(unpacker, collection as IList, UnpackHelpers.GetItemsCount(unpacker)); #endif // !UNITY }
protected internal override void UnpackToCore(Unpacker unpacker, IDictionary <TKey, TValue> collection) { if (this._collectionDeserializer != null) { // Fast path: this._collectionDeserializer.UnpackTo(unpacker, collection); } else { if (!unpacker.IsMapHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } this.UnpackToCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker)); } }
protected internal override object UnpackFromCore(Unpacker unpacker) #endif // !UNITY { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } var count = UnpackHelpers.GetItemsCount(unpacker); #if !UNITY var result = new T[count]; #else var result = Array.CreateInstance(this._itemType, count); #endif // !UNITY this.UnpackToCore(unpacker, result, count); return(result); }
private void ReadArrayMetadata(Unpacker metadataUnpacker, out int[] lengths, out int[] lowerBounds) { if (!metadataUnpacker.Read()) { throw SerializationExceptions.NewUnexpectedEndOfStream(); } if (!metadataUnpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } using (var lengthsUnpacker = metadataUnpacker.ReadSubtree()) { #if !UNITY lengths = this._int32ArraySerializer.UnpackFrom(lengthsUnpacker); #else lengths = this._int32ArraySerializer.UnpackFrom(lengthsUnpacker) as int[]; #endif // !UNITY } if (!metadataUnpacker.Read()) { throw SerializationExceptions.NewUnexpectedEndOfStream(); } if (!metadataUnpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } using (var lowerBoundsUnpacker = metadataUnpacker.ReadSubtree()) { #if !UNITY lowerBounds = this._int32ArraySerializer.UnpackFrom(lowerBoundsUnpacker); #else lowerBounds = this._int32ArraySerializer.UnpackFrom(lowerBoundsUnpacker) as int[]; #endif // !UNITY } }
protected internal override void UnpackToCore(Unpacker unpacker, T collection) { if (this._collectionDeserializer != null) { // Fast path: this._collectionDeserializer.UnpackTo(unpacker, collection); } else { if (this._addItem == null) { throw SerializationExceptions.NewUnpackToIsNotSupported(typeof(T), null); } if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } this.UnpackToCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker)); } }
protected internal override T UnpackFromCore(Unpacker unpacker) { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } if (this._collectionDeserializer != null) { // Fast path: return(( T )this._collectionDeserializer.UnpackFrom(unpacker)); } var itemsCount = UnpackHelpers.GetItemsCount(unpacker); var collection = ( T )(this._collectionConstructorWithoutCapacity != null ? this._collectionConstructorWithoutCapacity.Invoke(null) : this._collectionConstructorWithCapacity.Invoke(new object[] { itemsCount })); this.UnpackToCore(unpacker, collection, itemsCount); return(collection); }
protected override T[] UnpackFromCore(Unpacker unpacker) { MessagePackSerializer <T> serializer = base.OwnerContext.GetSerializer <T>(); if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } int itemsCount = UnpackHelpers.GetItemsCount(unpacker); T[] array = new T[itemsCount]; if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } for (int i = 0; i < itemsCount; i++) { if (!unpacker.Read()) { throw SerializationExceptions.NewMissingItem(i); } T val = default(T); if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader) { val = serializer.UnpackFrom(unpacker); } else { using (Unpacker unpacker2 = unpacker.ReadSubtree()) { val = serializer.UnpackFrom(unpacker2); } } array[i] = val; } return(array); }
protected override List <T> UnpackFromCore(Unpacker unpacker) { MessagePackSerializer <T> serializer = base.OwnerContext.GetSerializer <T>(); if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } int itemsCount = UnpackHelpers.GetItemsCount(unpacker); List <T> list = new List <T>(); if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } for (int i = 0; i < itemsCount; i++) { if (!unpacker.Read()) { throw SerializationExceptions.NewMissingItem(i); } T item = default(T); if (!unpacker.IsArrayHeader && !unpacker.IsMapHeader) { item = serializer.UnpackFrom(unpacker); } else { using (Unpacker unpacker2 = unpacker.ReadSubtree()) { item = serializer.UnpackFrom(unpacker2); } } list.Add(item); } return(list); }
public void UnpackFromMessage(Unpacker unpacker) { // Unpack fields are here: // temp variables long id; string name; // It should be packed as array because we use hand-made packing implementation above. if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } // Check items count. if (UnpackHelpers.GetItemsCount(unpacker) != 2) { throw SerializationExceptions.NewUnexpectedArrayLength(2, UnpackHelpers.GetItemsCount(unpacker)); } // Unpack fields here: if (!unpacker.ReadInt64(out id)) { throw SerializationExceptions.NewMissingProperty("Id"); } this.Id = id; if (!unpacker.ReadString(out name)) { throw SerializationExceptions.NewMissingProperty("Name"); } this.Name = name; // ...Instead, you can unpack from map as follows: //if ( !unpacker.IsMapHeader ) //{ // throw SerializationExceptions.NewIsNotMapHeader(); //} //// Check items count. //if ( UnpackHelpers.GetItemsCount( unpacker ) != 2 ) //{ // throw SerializationExceptions.NewUnexpectedArrayLength( 2, UnpackHelpers.GetItemsCount( unpacker ) ); //} //// Unpack fields here: //for ( int i = 0; i < 2 /* known count of fields */; i++ ) //{ // // Unpack and verify key of entry in map. // string key; // if ( !unpacker.ReadString( out key ) ) // { // // Missing key, incorrect. // throw SerializationExceptions.NewUnexpectedEndOfStream(); // } // switch ( key ) // { // case "Id": // { // if ( !unpacker.ReadInt64( out id ) ) // { // throw SerializationExceptions.NewMissingProperty( "Id" ); // } // // this.Id = id; // break; // } // case "Name": // { // if ( !unpacker.ReadString( out name ) ) // { // throw SerializationExceptions.NewMissingProperty( "Name" ); // } // // this.Name = name; // break; // } // // Note: You should ignore unknown fields for forward compatibility. // } //} }
protected internal override object UnpackFromCore(Unpacker unpacker) #endif // !UNITY { if (!unpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } if (UnpackHelpers.GetItemsCount(unpacker) != 2) { throw new SerializationException("Multidimensional array must be encoded as 2 element array."); } using (var wholeUnpacker = unpacker.ReadSubtree()) { if (!wholeUnpacker.Read()) { throw SerializationExceptions.NewUnexpectedEndOfStream(); } MessagePackExtendedTypeObject metadata; try { metadata = wholeUnpacker.LastReadData.AsMessagePackExtendedTypeObject(); } catch (InvalidOperationException ex) { throw new SerializationException("Multidimensional array must be encoded as ext type.", ex); } if (metadata.TypeCode != MultidimensionalArray) { throw new SerializationException( String.Format( CultureInfo.CurrentCulture, "Multidimensional array must be encoded as ext type {0}.", MultidimensionalArray ) ); } int[] lengths, lowerBounds; using (var arrayMetadata = new MemoryStream(metadata.Body)) using (var metadataUnpacker = Unpacker.Create(arrayMetadata)) { if (!metadataUnpacker.Read()) { throw SerializationExceptions.NewUnexpectedEndOfStream(); } if (!metadataUnpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } if (UnpackHelpers.GetItemsCount(metadataUnpacker) != 2) { throw new SerializationException("Multidimensional metadata array must be encoded as 2 element array."); } this.ReadArrayMetadata(metadataUnpacker, out lengths, out lowerBounds); } #if SILVERLIGHT // Simulate lowerbounds because Array.Initialize() in Silverlight does not support lowerbounds. for (var i = 0; i < lowerBounds.Length; i++) { lengths[i] += lowerBounds[i]; } #endif // SILVERLIGHT if (!wholeUnpacker.Read()) { throw SerializationExceptions.NewUnexpectedEndOfStream(); } if (!wholeUnpacker.IsArrayHeader) { throw SerializationExceptions.NewIsNotArrayHeader(); } using (var arrayUnpacker = wholeUnpacker.ReadSubtree()) { var result = Array.CreateInstance( #if !UNITY typeof(TItem), #else this._itemType, #endif // !UNITY #if !SILVERLIGHT lengths, lowerBounds #else lengths #endif // !SILVERLIGHT ); var totalLength = UnpackHelpers.GetItemsCount(arrayUnpacker); if (totalLength > 0) { ForEach( result, totalLength, lowerBounds, lengths, indices => { // ReSharper disable AccessToDisposedClosure if (!arrayUnpacker.Read()) { throw SerializationExceptions.NewUnexpectedEndOfStream(); } result.SetValue( this._itemSerializer.UnpackFrom(arrayUnpacker), indices ); // ReSharper restore AccessToDisposedClosure } ); } #if !UNITY return(( TArray )( object )result); #else return(result); #endif // !UNITY } } }