Exemple #1
0
		private static void UnpackOne( Unpacker unpacker )
		{
			if ( !unpacker.Read() )
			{
				throw new UnpackException( "Cannot unpack MesssagePack object from the stream." );
			}
		}
        public void UnpackFromMessage(Unpacker unpacker)
        {
            if (RequestType != (MessageType)unpacker.LastReadData.AsByte())
                throw new InvalidMessagePackStreamException("Invalid message type");

            UnpackFromMessageCore(unpacker);
        }
Exemple #3
0
		private static void FeedFile( Unpacker pac, String path )
		{
			var input = new FileStream( path, FileMode.Open );
			byte[] buffer = new byte[ 64 * 1024 ];
			while ( true )
			{
				int count = input.Read( buffer, 0, buffer.Length );
				if ( count <= 0 )
				{
					break;
				}
				pac.Feed( buffer );
			}
		}
Exemple #4
0
		public void UnpackFromMessage( Unpacker unpacker )
		{
			if ( !unpacker.IsArrayHeader || unpacker.LastReadData.AsInt32() != 5 )
			{
				throw new ArgumentException( "Must be 5 element array." );
			}

			var asList = unpacker.UnpackSubtree().Value.AsList();

			uri = asList[ 0 ].AsString();
			title = asList[ 1 ].AsString();
			width = asList[ 2 ].AsInt32();
			height = asList[ 3 ].AsInt32();
			size = asList[ 4 ].AsInt32();
		}
Exemple #5
0
		private static bool IsNil( Unpacker unpacker )
		{
			return unpacker.Data.HasValue && unpacker.Data.Value.IsNil;
		}
 protected override ByteArrayUnpacker CreateUnpacker(byte[] source, int offset)
 {
     return(Unpacker.Create(source, offset, new UnpackerOptions {
         ValidationLevel = UnpackerValidationLevel.Collection
     }));
 }
 public void TestCreate_ByteArray_Int32_ArrayIsNull()
 {
     Assert.Throws <ArgumentNullException>(() => { using (Unpacker.Create(default(byte[]), 0)) { } });
 }
Exemple #8
0
		private static MessagePackObjectDictionary UnpackDictionaryCore( Unpacker unpacker )
		{
			if ( IsNil( unpacker ) )
			{
				return null;
			}


			uint count = ( uint )unpacker.Data.Value;
			if ( count > Int32.MaxValue )
			{
				throw new MessageNotSupportedException( "The map which count is greater than Int32.MaxValue is not supported." );
			}

			var result = new MessagePackObjectDictionary( unchecked( ( int )count ) );
			for ( int i = 0; i < count; i++ )
			{
				var key = UnpackObjectCore( unpacker );
				var value = UnpackObjectCore( unpacker );
				try
				{
					result.Add( key, value );
				}
				catch ( ArgumentException ex )
				{
					throw new InvalidMessagePackStreamException( "The dicationry key is duplicated in the stream.", ex );
				}
			}

			return result;
		}
 /// <summary>
 /// Deserializes the target object
 /// </summary>
 /// <param name="unpacker"></param>
 /// <returns></returns>
 protected override T UnpackFromCore(MsgPack.Unpacker unpacker)
 {
     return(_unpack(unpacker));
 }
 public void UnpackFromMessage(Unpacker unpacker)
 {
     unpacker.ReadInt32(out count);
     unpacker.ReadString(out data);
 }
 protected override long GetOffset(Unpacker unpacker)
 {
     return((( ByteArrayUnpacker )unpacker).Offset);
 }
Exemple #12
0
        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);
        }
 public void TestCreate_Stream_PackerUnpackerStreamOptions_UnpackerOptions_StreamIsNull()
 {
     Assert.Throws <ArgumentNullException>(() => { using (Unpacker.Create(default(Stream), default(PackerUnpackerStreamOptions), default(UnpackerOptions))) { } });
 }
 protected override bool CanRevert(Unpacker unpacker)
 {
     return(true);
 }
 public void TestCreate_Stream_Boolean_StreamIsNull()
 {
     Assert.Throws <ArgumentNullException>(() => { using (Unpacker.Create(default(Stream), true)) { } });
 }
 public void TestCreate_ByteArray_Int32_TooLargeOffset()
 {
     Assert.Throws <ArgumentException>(() => { using (Unpacker.Create(new byte[1], 2)) { } });
 }
 public void TestCreate_ByteArray_Int32_NegativeOffset()
 {
     Assert.Throws <ArgumentOutOfRangeException>(() => { using (Unpacker.Create(new byte[1], -1)) { } });
 }
        public void TestDeepNestedArray()
        {
            using (var stream = new MemoryStream())
            {
                var packer = Packer.Create(stream);
                packer.Pack(
                    new[]
                {
                    new MessagePackObject(
                        new[]
                    {
                        new MessagePackObject(
                            new [] { new MessagePackObject("1-1-1"), new MessagePackObject("1-1-2"), new MessagePackObject("1-1-3") }
                            ),
                        new MessagePackObject(
                            new [] { new MessagePackObject("1-2-1"), new MessagePackObject("1-2-2"), new MessagePackObject("1-2-3") }
                            ),
                        new MessagePackObject(
                            new [] { new MessagePackObject("1-3-1"), new MessagePackObject("1-3-2"), new MessagePackObject("1-3-3") }
                            ),
                    }
                        ),
                    new MessagePackObject(
                        new[]
                    {
                        new MessagePackObject(
                            new [] { new MessagePackObject("2-1-1"), new MessagePackObject("2-1-2"), new MessagePackObject("2-1-3") }
                            ),
                        new MessagePackObject(
                            new [] { new MessagePackObject("2-2-1"), new MessagePackObject("2-2-2"), new MessagePackObject("2-2-3") }
                            ),
                        new MessagePackObject(
                            new [] { new MessagePackObject("2-3-1"), new MessagePackObject("2-3-2"), new MessagePackObject("2-3-3") }
                            ),
                    }
                        ),
                    new MessagePackObject(
                        new[]
                    {
                        new MessagePackObject(
                            new [] { new MessagePackObject("3-1-1"), new MessagePackObject("3-1-2"), new MessagePackObject("3-1-3") }
                            ),
                        new MessagePackObject(
                            new [] { new MessagePackObject("3-2-1"), new MessagePackObject("3-2-2"), new MessagePackObject("3-2-3") }
                            ),
                        new MessagePackObject(
                            new [] { new MessagePackObject("3-3-1"), new MessagePackObject("3-3-2"), new MessagePackObject("3-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++)
                            {
                                using (Unpacker subtreeReader3 = subtreeReader2.ReadSubtree())
                                {
                                    Assert.That(subtreeReader3.IsArrayHeader);
                                    Assert.That(subtreeReader3.ItemsCount, Is.EqualTo(3));
                                    for (int k = 1; subtreeReader3.Read(); k++)
                                    {
                                        Assert.That(subtreeReader3.LastReadData.AsString(), Is.EqualTo(i + "-" + j + "-" + k));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 protected abstract void UnpackFromMessageCore(Unpacker unpacker);
Exemple #20
0
 private static T UnpackCore <T>(Unpacker source, SerializationContext context)
 {
     return(MessagePackSerializer.Create <T>(context).UnpackFrom(source));
 }
 protected override void UnpackFromMessageCore(Unpacker unpacker)
 {
     RpcMessageSerializer.ReadNext(unpacker);
     _str = (string)unpacker.LastReadData;
 }
        /// <summary>
        /// Unpack from msgpack'd stream
        /// </summary>
        /// <param name="unpacker">
        /// The msgpack unpacker
        /// </param>
        /// <exception cref="SerializationException">
        /// Unsuitable data encountered
        /// </exception>
        public void UnpackFromMessage(Unpacker unpacker)
        {
            int numberOfItems = unpacker.Data.Value.AsInt32();

            while (numberOfItems > 0)
            {
                unpacker.ReadItem();

                if (unpacker.Data.Value.IsTypeOf(typeof(Int32)) == true)
                {
                    int temp = unpacker.Data.Value.AsInt32();
                    this.Values.Add(temp);
                }
                else if (unpacker.Data.Value.IsTypeOf(typeof(Single)) == true)
                {
                    float temp = unpacker.Data.Value.AsSingle();
                    this.Values.Add(temp);
                }
                else if (unpacker.Data.Value.IsTypeOf(typeof(String)) == true)
                {
                    string temp = unpacker.Data.Value.AsStringUtf8();
                    this.Values.Add(temp);
                }
                else
                {
                    throw new SerializationException("Unpacker found no suitable data inside Function Arguments!");
                }

                numberOfItems--;
            }
        }
 protected override Unpacker CreateUnpacker(Stream stream)
 {
     return(Unpacker.Create(stream, PackerUnpackerStreamOptions.None, new UnpackerOptions {
         ValidationLevel = UnpackerValidationLevel.Collection
     }));
 }
Exemple #24
0
 protected override Delegate UnpackFromCore(MsgPack.Unpacker unpacker)
 {
     throw new NotImplementedException();
 }
Exemple #25
0
		private static void VerifyIsScalar( Unpacker unpacker )
		{
			if ( unpacker.IsArrayHeader || unpacker.IsMapHeader )
			{
				throw new MessageTypeException( "The underlying stream is not scalar type." );
			}
		}
Exemple #26
0
        public void TestReadSubtree_NestedMap_Success()
        {
            using (var buffer = new MemoryStream(new byte[] { 0x84, 0x1, 0x81, 0x1, 0x1, 0x2, 0x80, 0x3, 0xC0, 0x4, 0x82, 0x1, 0x1, 0x2, 0x2, 0x81, 0x1, 0x1 }))
                using (var rootUnpacker = Unpacker.Create(buffer))
                {
                    Assert.That(rootUnpacker.Read(), Is.True);

                    using (var subTreeUnpacker = rootUnpacker.ReadSubtree())
                    {
                        Assert.That(subTreeUnpacker.Read(), Is.True);
                        Assert.That(subTreeUnpacker.LastReadData.Equals(1));
                        Assert.That(subTreeUnpacker.Read(), Is.True);

                        using (var subSubtreeUnpacker = subTreeUnpacker.ReadSubtree())
                        {
                            Assert.That(subSubtreeUnpacker.Read(), Is.True);
                            Assert.That(subSubtreeUnpacker.LastReadData.Equals(1));
                            Assert.That(subSubtreeUnpacker.Read(), Is.True);
                            Assert.That(subSubtreeUnpacker.LastReadData.Equals(1));
                            Assert.That(subSubtreeUnpacker.Read(), Is.False);
                        }

                        Assert.That(subTreeUnpacker.Read(), Is.True);
                        Assert.That(subTreeUnpacker.LastReadData.Equals(2));
                        Assert.That(subTreeUnpacker.Read(), Is.True);

                        using (var subSubtreeUnpacker = subTreeUnpacker.ReadSubtree())
                        {
                            Assert.That(subSubtreeUnpacker.Read(), Is.False);
                        }

                        Assert.That(subTreeUnpacker.Read(), Is.True);
                        Assert.That(subTreeUnpacker.LastReadData.Equals(3));
                        Assert.That(subTreeUnpacker.Read(), Is.True);
                        Assert.That(subTreeUnpacker.LastReadData.IsNil);

                        Assert.That(subTreeUnpacker.Read(), Is.True);
                        Assert.That(subTreeUnpacker.LastReadData.Equals(4));
                        Assert.That(subTreeUnpacker.Read(), Is.True);

                        using (var subSubtreeUnpacker = subTreeUnpacker.ReadSubtree())
                        {
                            Assert.That(subSubtreeUnpacker.Read(), Is.True);
                            Assert.That(subSubtreeUnpacker.LastReadData.Equals(1));
                            Assert.That(subSubtreeUnpacker.Read(), Is.True);
                            Assert.That(subSubtreeUnpacker.LastReadData.Equals(1));
                            Assert.That(subSubtreeUnpacker.Read(), Is.True);
                            Assert.That(subSubtreeUnpacker.LastReadData.Equals(2));
                            Assert.That(subSubtreeUnpacker.Read(), Is.True);
                            Assert.That(subSubtreeUnpacker.LastReadData.Equals(2));
                            Assert.That(subSubtreeUnpacker.Read(), Is.False);
                        }

                        Assert.That(subTreeUnpacker.Read(), Is.False);
                    }

                    Assert.That(rootUnpacker.Read(), Is.True);

                    using (var subTreeUnpacker = rootUnpacker.ReadSubtree())
                    {
                        Assert.That(subTreeUnpacker.Read(), Is.True);
                        Assert.That(subTreeUnpacker.LastReadData.Equals(1));
                        Assert.That(subTreeUnpacker.Read(), Is.True);
                        Assert.That(subTreeUnpacker.LastReadData.Equals(1));
                        Assert.That(subTreeUnpacker.Read(), Is.False);
                    }

                    Assert.That(rootUnpacker.Read(), Is.False);
                }
        }
 public void TestCreate_ByteArray_Int32_Empty()
 {
     Assert.Throws <ArgumentException>(() => { using (Unpacker.Create(new byte[0], 0)) { } });
 }
Exemple #28
0
		private static bool IsNil( Unpacker unpacker )
		{
#pragma warning disable 612,618
			return unpacker.Data.HasValue && unpacker.LastReadData.IsNil;
#pragma warning restore 612,618
		}
Exemple #29
0
 public void TestCreate_StreamIsNull()
 {
     Assert.Throws <ArgumentNullException>(() => { using (Unpacker.Create(null)) { } });
 }
		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 new SerializationException( "Is not in array header." );
			}

			// Check items count.
			if ( UnpackHelpers.GetItemsCount( unpacker ) != 2 )
			{
				throw new SerializationException( $"Array length should be 2, but {UnpackHelpers.GetItemsCount( unpacker )}" );
			}

			// Unpack fields here:
			if ( !unpacker.ReadInt64( out id ) )
			{
				throw new SerializationException( "Property Id is not found." );
			}

			this.Id = id;

			if ( !unpacker.ReadString( out name ) )
			{
				throw new SerializationException( "Property Name is not found." );
			}

			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.
			//	}
			//}
		}
Exemple #31
0
 private static T UnpackCore <T>(Unpacker source, SerializationContext context)
 {
     return(context.GetSerializer <T>().UnpackFrom(source));
 }
Exemple #32
0
		private static IList<MessagePackObject> UnpackArrayCore( Unpacker unpacker )
		{
			if ( IsNil( unpacker ) )
			{
				return null;
			}

			uint length = ( uint )unpacker.Data.Value;
			if ( length > Int32.MaxValue )
			{
				throw new MessageNotSupportedException( "The array which length is greater than Int32.MaxValue is not supported." );
			}

			var result = new MessagePackObject[ unchecked( ( int )length ) ];
			for ( int i = 0; i < result.Length; i++ )
			{
				result[ i ] = UnpackObjectCore( unpacker );
			}

			return result;
		}
        /// <summary>
        /// Unpack from msgpack'd stream
        /// </summary>
        /// <param name="unpacker">
        /// The msgpack unpacker
        /// </param>
        /// <exception cref="SerializationException">
        /// Unsuitable data encountered
        /// </exception>
        public void UnpackFromMessage(Unpacker unpacker)
        {
            int numberOfItems = unpacker.LastReadData.AsInt32();
            this.Values = new List<MessagePackObject>(numberOfItems);

            while (numberOfItems > 0)
            {
                unpacker.ReadItem();

                if (unpacker.LastReadData.IsTypeOf(typeof(Int32)) == true)
                {
                    this.Values.Add(unpacker.LastReadData.AsInt32());
                }
                else if (unpacker.LastReadData.IsTypeOf(typeof(Single)) == true)
                {
                    this.Values.Add(unpacker.LastReadData.AsSingle());
                }
                else if (unpacker.LastReadData.IsTypeOf(typeof(string)) == true)
                {
                    this.Values.Add(unpacker.LastReadData.AsStringUtf8());
                }
                else
                {
                    throw new SerializationException("Unpacker found no suitable data inside Function Arguments!");
                }

                numberOfItems--;
            }
        }
Exemple #34
0
		private static MessagePackObject UnpackObjectCore( Unpacker unpacker )
		{
			UnpackOne( unpacker );

			if ( unpacker.IsArrayHeader )
			{
				return new MessagePackObject( UnpackArrayCore( unpacker ), true );
			}
			else if ( unpacker.IsMapHeader )
			{
				return new MessagePackObject( UnpackDictionaryCore( unpacker ), true );
			}
			else
			{
				return unpacker.Data.Value;
			}
		}
Exemple #35
0
        /// <summary>
        ///     Unpacks the message from a MessagePack object
        ///     This method should not be called directly, use deserialize instead.
        /// </summary>
        /// <param name="unpacker">The unpacker</param>
        public void UnpackFromMessage(Unpacker unpacker)
        {
            string dcs, dac, dad, dbd, dbb, day, dau, dag, dai, daj, dak, dcg;
            int dbc;

            if (!unpacker.IsMapHeader) throw SerializationExceptions.NewIsNotMapHeader();

            if (UnpackHelpers.GetItemsCount(unpacker) != MapCount)
                throw SerializationExceptions.NewUnexpectedArrayLength(MapCount, UnpackHelpers.GetItemsCount(unpacker));

            for (var i = 0; i < MapCount; i++) {
                string key;

                if (!unpacker.ReadString(out key)) throw SerializationExceptions.NewUnexpectedEndOfStream();

                switch (key) {
                    case "DCS": {
                        if (!unpacker.ReadString(out dcs)) throw SerializationExceptions.NewMissingProperty("dcs");
                        Dcs = dcs;
                        break;
                    }
                    case "DAC": {
                        if (!unpacker.ReadString(out dac)) throw SerializationExceptions.NewMissingProperty("dac");
                        Dac = dac;
                        break;
                    }
                    case "DAD": {
                        if (!unpacker.ReadString(out dad)) throw SerializationExceptions.NewMissingProperty("dad");
                        Dad = dad;
                        break;
                    }
                    case "DBD": {
                        if (!unpacker.ReadString(out dbd)) throw SerializationExceptions.NewMissingProperty("dbd");
                        Dbd = DateTime.Parse(dbd);
                        break;
                    }
                    case "DBB": {
                        if (!unpacker.ReadString(out dbb)) throw SerializationExceptions.NewMissingProperty("dbb");
                        Dbb = DateTime.Parse(dbb);
                        break;
                    }
                    case "DBC": {
                        if (!unpacker.ReadInt32(out dbc)) throw SerializationExceptions.NewMissingProperty("dbc");
                        Dbc = (Sex) dbc;
                        break;
                    }
                    case "DAY": {
                        if (!unpacker.ReadString(out day)) throw SerializationExceptions.NewMissingProperty("day");
                        Day = GetEyeColor(day);
                        break;
                    }
                    case "DAU": {
                        if (!unpacker.ReadString(out dau)) throw SerializationExceptions.NewMissingProperty("dau");
                        Dau = new Height {AnsiFormat = dau};
                        break;
                    }
                    case "DAG": {
                        if (!unpacker.ReadString(out dag)) throw SerializationExceptions.NewMissingProperty("dag");
                        Dag = dag;
                        break;
                    }
                    case "DAI": {
                        if (!unpacker.ReadString(out dai)) throw SerializationExceptions.NewMissingProperty("dai");
                        Dai = dai;
                        break;
                    }
                    case "DAJ": {
                        if (!unpacker.ReadString(out daj)) throw SerializationExceptions.NewMissingProperty("daj");
                        Daj = daj;
                        break;
                    }
                    case "DAK": {
                        if (!unpacker.ReadString(out dak)) throw SerializationExceptions.NewMissingProperty("dak");
                        Dak = new PostalCode {AnsiFormat = dak};
                        break;
                    }
                    case "DCG": {
                        if (!unpacker.ReadString(out dcg)) throw SerializationExceptions.NewMissingProperty("dcg");
                        Dcg = dcg;
                        break;
                    }
                    case "ZAA": {
                        if (!unpacker.Read()) throw SerializationExceptions.NewMissingProperty("zaa");
                        var ms = new MemoryStream(unpacker.LastReadData.AsBinary());
                        Image = Image.FromStream(ms);
                        break;
                    }
                    case "ZAB": {
                        if (!unpacker.Read()) throw SerializationExceptions.NewMissingProperty("zab");
                        Fingerprint = new Fingerprint {AsIsoTemplate = unpacker.LastReadData.AsBinary()};
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// </summary>
        /// <param name="unpacker">
        /// </param>
        public void UnpackFromMessage(Unpacker unpacker)
        {
            // Read the type name
            this.typeName = unpacker.LastReadData.AsString();

            // Read the data object as byte array
            byte[] temp;
            unpacker.ReadBinary(out temp);

            // Create a message serializer object
            IMessagePackSingleObjectSerializer ser = MessagePackSerializer.Create(Type.GetType(this.typeName));

            // Unpack the message's data object
            this.dataObject = (MessageBase)ser.UnpackSingleObject(temp);
        }
Exemple #37
0
 private static bool IsNil(Unpacker unpacker)
 {
     return(unpacker.Data.HasValue && unpacker.Data.Value.IsNil);
 }