protected internal override T UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsMapHeader)
            {
                throw SerializationExceptions.NewIsNotMapHeader();
            }

            var buffer = new KeyValuePair <TKey, TValue> [UnpackHelpers.GetItemsCount(unpacker)];

            using (var subTreeUnpacker = unpacker.ReadSubtree())
            {
                for (int i = 0; i < buffer.Length; i++)
                {
                    if (!subTreeUnpacker.Read())
                    {
                        throw SerializationExceptions.NewUnexpectedEndOfStream();
                    }

                    var key = this._keySerializer.UnpackFrom(unpacker);

                    if (!subTreeUnpacker.Read())
                    {
                        throw SerializationExceptions.NewUnexpectedEndOfStream();
                    }

                    var value = this._valueSerializer.UnpackFrom(unpacker);

                    buffer[i] = new KeyValuePair <TKey, TValue>(key, value);
                }
            }

            return(_factory(buffer));
        }
        protected internal override void UnpackToCore(Unpacker unpacker, NameValueCollection collection)
        {
            if (!unpacker.IsMapHeader)
            {
                throw SerializationExceptions.NewIsNotMapHeader();
            }

            UnpackToCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker));
        }
Exemplo n.º 3
0
        protected internal override void UnpackToCore(Unpacker unpacker, Dictionary <TKey, TValue> collection)
        {
            if (!unpacker.IsMapHeader)
            {
                throw SerializationExceptions.NewIsNotMapHeader();
            }

            this.UnpackToCore(unpacker, collection, UnpackHelpers.GetItemsCount(unpacker));
        }
        protected internal override NameValueCollection UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsMapHeader)
            {
                throw SerializationExceptions.NewIsNotMapHeader();
            }

            var count      = UnpackHelpers.GetItemsCount(unpacker);
            var collection = new NameValueCollection(count);

            UnpackToCore(unpacker, collection, count);
            return(collection);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
0
        protected internal override Dictionary <TKey, TValue> UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsMapHeader)
            {
                throw SerializationExceptions.NewIsNotMapHeader();
            }

            var count      = UnpackHelpers.GetItemsCount(unpacker);
            var collection = new Dictionary <TKey, TValue>(count);

            this.UnpackToCore(unpacker, collection, count);
            return(collection);
        }
        protected internal override IDictionary <TKey, TValue> UnpackFromCore(Unpacker unpacker)
        {
            if (!unpacker.IsMapHeader)
            {
                throw SerializationExceptions.NewIsNotMapHeader();
            }

            if (this._collectionDeserializer != null)
            {
                // Fast path:
                return(this._collectionDeserializer.UnpackFrom(unpacker) as IDictionary <TKey, TValue>);
            }

            var itemsCount = UnpackHelpers.GetItemsCount(unpacker);
            var collection =
                (this._collectionConstructorWithoutCapacity != null
                                        ? this._collectionConstructorWithoutCapacity.Invoke(null)
                                        : this._collectionConstructorWithCapacity.Invoke(new object[] { itemsCount })) as IDictionary <TKey, TValue>;

            this.UnpackToCore(unpacker, collection, itemsCount);
            return(collection);
        }
Exemplo n.º 8
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;
                }
                }
            }
        }