Ejemplo n.º 1
0
        /// <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--;
            }
        }
Ejemplo n.º 2
0
        /// <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--;
            }
        }