Esempio n. 1
0
        protected internal sealed override DictionaryEntry UnpackFromCore(Unpacker unpacker)
        {
            object key          = null;
            object value        = null;
            bool   isKeyFound   = false;
            bool   isValueFound = false;

            while (unpacker.Read())
            {
                if (!unpacker.Data.HasValue)
                {
                    throw SerializationExceptions.NewUnexpectedEndOfStream();
                }

                switch (unpacker.Data.Value.DeserializeAsString())
                {
                case "Key":
                {
                    if (!unpacker.Read())
                    {
                        throw SerializationExceptions.NewUnexpectedEndOfStream();
                    }

                    isKeyFound = true;
                    key        = unpacker.Data.Value;
                    break;
                }

                case "Value":
                {
                    if (!unpacker.Read())
                    {
                        throw SerializationExceptions.NewUnexpectedEndOfStream();
                    }

                    isValueFound = true;
                    value        = unpacker.Data.Value;
                    break;
                }
                }
            }

            if (!isKeyFound)
            {
                throw SerializationExceptions.NewMissingProperty("Key");
            }

            if (!isValueFound)
            {
                throw SerializationExceptions.NewMissingProperty("Value");
            }

            return(new DictionaryEntry(key, value));
        }
        protected internal sealed override DictionaryEntry UnpackFromCore(Unpacker unpacker)
        {
            object key   = null;
            object obj3  = null;
            bool   flag  = false;
            bool   flag2 = false;

            while (unpacker.Read())
            {
                if (!unpacker.Data.HasValue)
                {
                    throw SerializationExceptions.NewUnexpectedEndOfStream();
                }
                string str = unpacker.Data.Value.DeserializeAsString();
                if (str != null)
                {
                    if (!(str == "Key"))
                    {
                        if (str == "Value")
                        {
                            goto Label_0090;
                        }
                    }
                    else
                    {
                        if (!unpacker.Read())
                        {
                            throw SerializationExceptions.NewUnexpectedEndOfStream();
                        }
                        flag = true;
                        key  = unpacker.Data.Value;
                    }
                }
                continue;
Label_0090:
                if (!unpacker.Read())
                {
                    throw SerializationExceptions.NewUnexpectedEndOfStream();
                }
                flag2 = true;
                obj3  = unpacker.Data.Value;
            }
            if (!flag)
            {
                throw SerializationExceptions.NewMissingProperty("Key");
            }
            if (!flag2)
            {
                throw SerializationExceptions.NewMissingProperty("Value");
            }
            return(new DictionaryEntry(key, obj3));
        }
        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 DictionaryEntry UnpackFromCore(Unpacker unpacker)
        {
            if (unpacker.IsArrayHeader)
            {
                MessagePackObject key;
                MessagePackObject value;

                if (!unpacker.ReadObject(out key))
                {
                    throw SerializationExceptions.NewUnexpectedEndOfStream();
                }

                if (!unpacker.ReadObject(out value))
                {
                    throw SerializationExceptions.NewUnexpectedEndOfStream();
                }

                return(new DictionaryEntry(key, value));
            }
            else
            {
                // Previous DictionaryEntry serializer accidentally pack it as map...
                MessagePackObject key   = default(MessagePackObject);
                MessagePackObject value = default(MessagePackObject);
                bool   isKeyFound       = false;
                bool   isValueFound     = false;
                string propertyName;

                while ((!isKeyFound || !isValueFound) && unpacker.ReadString(out propertyName))
                {
                    switch (propertyName)
                    {
                    case "Key":
                    {
                        if (!unpacker.ReadObject(out key))
                        {
                            throw SerializationExceptions.NewUnexpectedEndOfStream();
                        }

                        isKeyFound = true;
                        break;
                    }

                    case "Value":
                    {
                        if (!unpacker.ReadObject(out value))
                        {
                            throw SerializationExceptions.NewUnexpectedEndOfStream();
                        }

                        isValueFound = true;
                        break;
                    }
                    }
                }

                if (!isKeyFound)
                {
                    throw SerializationExceptions.NewMissingProperty("Key");
                }

                if (!isValueFound)
                {
                    throw SerializationExceptions.NewMissingProperty("Value");
                }

                return(new DictionaryEntry(key, value));
            }
        }
Esempio n. 5
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;
                }
                }
            }
        }