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 TestNestedArray() { using (var stream = new MemoryStream()) { var packer = Packer.Create(stream); packer.PackArray( new[] { new MessagePackObject(new[] { new MessagePackObject("1-1"), new MessagePackObject("1-2"), new MessagePackObject("1-3") }), new MessagePackObject(new[] { new MessagePackObject("2-1"), new MessagePackObject("2-2"), new MessagePackObject("2-3") }), new MessagePackObject(new[] { new MessagePackObject("3-1"), new MessagePackObject("3-2"), new MessagePackObject("3-3") }), } ); stream.Position = 0; var unpacker = Unpacker.Create(stream); Assert.That(unpacker.Read()); using (Unpacker subtreeReader1 = unpacker.ReadSubtree()) { Assert.That(subtreeReader1.IsArrayHeader); Assert.That(subtreeReader1.ItemsCount, Is.EqualTo(3)); for (int i = 1; subtreeReader1.Read(); i++) { using (Unpacker subtreeReader2 = subtreeReader1.ReadSubtree()) { Assert.That(subtreeReader2.IsArrayHeader); Assert.That(subtreeReader2.ItemsCount, Is.EqualTo(3)); for (int j = 1; subtreeReader2.Read(); j++) { Assert.That(subtreeReader2.LastReadData.AsString(), Is.EqualTo(i + "-" + j)); } } } } } }
protected override IO.Ably.Message UnpackFromCore(MsgPack.Unpacker unpacker) { IO.Ably.Message result = default(IO.Ably.Message); result = new IO.Ably.Message(); int itemsCount0 = default(int); itemsCount0 = MsgPack.Serialization.UnpackHelpers.GetItemsCount(unpacker); for (int i = 0; (i < itemsCount0); i = (i + 1)) { string key = default(string); string nullable7 = default(string); nullable7 = MsgPack.Serialization.UnpackHelpers.UnpackStringValue(unpacker, typeof(IO.Ably.Message), "MemberName"); if (((nullable7 == null) == false)) { key = nullable7; } else { throw MsgPack.Serialization.SerializationExceptions.NewNullIsProhibited("MemberName"); } if ((key == "timestamp")) { System.Nullable <System.DateTimeOffset> nullable15 = default(System.Nullable <System.DateTimeOffset>); if ((unpacker.Read() == false)) { throw MsgPack.Serialization.SerializationExceptions.NewMissingItem(i); } if (((unpacker.IsArrayHeader == false) && (unpacker.IsMapHeader == false))) { nullable15 = this._serializer2.UnpackFrom(unpacker); } else { MsgPack.Unpacker disposable4 = default(MsgPack.Unpacker); disposable4 = unpacker.ReadSubtree(); try { nullable15 = this._serializer2.UnpackFrom(disposable4); } finally { if (((disposable4 == null) == false)) { disposable4.Dispose(); } } } if (nullable15.HasValue) { result.Timestamp = nullable15; } } else { if ((key == "name")) { string nullable14 = default(string); nullable14 = MsgPack.Serialization.UnpackHelpers.UnpackStringValue(unpacker, typeof(IO.Ably.Message), "System.String name"); if (((nullable14 == null) == false)) { result.Name = nullable14; } } else { if ((key == "id")) { string nullable13 = default(string); nullable13 = MsgPack.Serialization.UnpackHelpers.UnpackStringValue(unpacker, typeof(IO.Ably.Message), "System.String id"); if (((nullable13 == null) == false)) { result.Id = nullable13; } } else { if ((key == "encoding")) { string nullable12 = default(string); nullable12 = MsgPack.Serialization.UnpackHelpers.UnpackStringValue(unpacker, typeof(IO.Ably.Message), "System.String encoding"); if (((nullable12 == null) == false)) { result.Encoding = nullable12; } } else { if ((key == "data")) { object nullable10 = default(object); if ((unpacker.Read() == false)) { throw MsgPack.Serialization.SerializationExceptions.NewMissingItem(i); } if (((unpacker.IsArrayHeader == false) && (unpacker.IsMapHeader == false))) { nullable10 = this._serializer1.UnpackFrom(unpacker); } else { MsgPack.Unpacker disposable2 = default(MsgPack.Unpacker); disposable2 = unpacker.ReadSubtree(); try { nullable10 = this._serializer1.UnpackFrom(disposable2); } finally { if (((disposable2 == null) == false)) { disposable2.Dispose(); } } } if (((nullable10 == null) == false)) { if (nullable10 is MsgPack.MessagePackObject) { nullable10 = ((MessagePackObject)nullable10).ToObject(); if (nullable10 is MessagePackObject[]) { result.Data = ((MessagePackObject[])nullable10).Select(x => x.ToObject()).ToArray(); } else { result.Data = nullable10; } } else { result.Data = nullable10; } } } else { if ((key == "connectionId")) { string nullable9 = default(string); nullable9 = MsgPack.Serialization.UnpackHelpers.UnpackStringValue(unpacker, typeof(IO.Ably.Message), "System.String connectionId"); if (((nullable9 == null) == false)) { result.ConnectionId = nullable9; } } else { if ((key == "clientId")) { string nullable8 = default(string); nullable8 = MsgPack.Serialization.UnpackHelpers.UnpackStringValue(unpacker, typeof(IO.Ably.Message), "System.String clientId"); if (((nullable8 == null) == false)) { result.ClientId = nullable8; } } else { unpacker.Skip(); } } } } } } } } return(result); }