protected override void PackToCore(Packer packer, Quaternion objectTree)
 {
     packer.PackArrayHeader(4);
     packer.Pack(objectTree.x);
     packer.Pack(objectTree.y);
     packer.Pack(objectTree.z);
     packer.Pack(objectTree.w);
 }
Beispiel #2
0
		public void PackToMessage( Packer pk, PackingOptions options )
		{
			pk.PackArrayHeader( 5 );
			pk.PackString( uri );
			pk.PackString( title );
			pk.Pack( width );
			pk.Pack( height );
			pk.Pack( size );
		}
Beispiel #3
0
 public void PackToMessage(Packer pk, PackingOptions options)
 {
     pk.PackArrayHeader(5);
     pk.PackString(uri);
     pk.PackString(title);
     pk.Pack(width);
     pk.Pack(height);
     pk.Pack(size);
 }
        protected override void PackToCore(Packer packer, T[] objectTree)
        {
            MessagePackSerializer <T> serializer = base.OwnerContext.GetSerializer <T>();

            packer.PackArrayHeader(objectTree.Length);
            foreach (T objectTree2 in objectTree)
            {
                serializer.PackTo(packer, objectTree2);
            }
        }
        protected override void PackToCore(Packer packer, List <T> objectTree)
        {
            MessagePackSerializer <T> serializer = base.OwnerContext.GetSerializer <T>();

            T[] array = objectTree.ToArray();
            packer.PackArrayHeader(array.Length);
            T[] array2 = array;
            foreach (T objectTree2 in array2)
            {
                serializer.PackTo(packer, objectTree2);
            }
        }
		public void PackToMessage( Packer packer, PackingOptions options )
		{
			// Pack fields are here:
			// First, record total fields size.
			packer.PackArrayHeader( 2 );
			packer.Pack( this.Id );
			packer.PackString( this.Name );

			// ...Instead, you can pack as map as follows:
			// packer.PackMapHeader( 2 );
			// packer.Pack( "Id" );
			// packer.Pack( this.Id );
			// packer.Pack( "Name" );
			// packer.Pack( this.Name );
		}
Beispiel #7
0
        internal static void PackCollectionCore <T>(Packer source, IEnumerable <T> collection, MessagePackSerializer <T> itemSerializer)
        {
            // ReSharper disable once CompareNonConstrainedGenericWithNull
            if (collection == null)
            {
                source.PackNull();
                return;
            }

            // ReSharper disable once SuspiciousTypeConversion.Global
            var asPackable = collection as IPackable;

            if (asPackable != null)
            {
                asPackable.PackToMessage(source, new PackingOptions());
                return;
            }

            int             count;
            ICollection <T> asCollectionT;
            ICollection     asCollection;

            if ((asCollectionT = collection as ICollection <T>) != null)
            {
                count = asCollectionT.Count;
            }
            else if ((asCollection = collection as ICollection) != null)
            {
                count = asCollection.Count;
            }
            else
            {
                var asArray = collection.ToArray();
                count      = asArray.Length;
                collection = asArray;
            }

            source.PackArrayHeader(count);
            foreach (var item in collection)
            {
                itemSerializer.PackTo(source, item);
            }
        }
 /// <summary>
 /// Use msgpack to compress the data
 /// </summary>
 /// <param name="packer">
 /// The msgpack packer
 /// </param>
 /// <param name="options">
 /// msgpack packing options
 /// </param>
 public void PackToMessage(Packer packer, PackingOptions options)
 {
     packer.PackArrayHeader(this.Values.Count);
     foreach (object obj in this.Values)
     {
         if (obj.GetType() == typeof(string))
         {
             string temp = (string)obj;
             packer.PackString(temp, Encoding.GetEncoding("UTF-8"));
         }
         else if (obj.GetType() == typeof(Single))
         {
             float temp = (Single)obj;
             packer.Pack<float>(temp);
         }
         else if (obj.GetType() == typeof(int))
         {
             int temp = (Int32)obj;
             packer.Pack(temp);
         }
     }
 }
 /// <summary>
 /// Use msgpack to compress the data
 /// </summary>
 /// <param name="packer">
 /// The msgpack packer
 /// </param>
 /// <param name="options">
 /// msgpack packing options
 /// </param>
 public void PackToMessage(Packer packer, PackingOptions options)
 {
     packer.PackArrayHeader(this.Values.Count);
     foreach (MessagePackObject obj in this.Values)
     {
         if (obj.IsTypeOf(typeof(string)) == true)
         {
             string temp = obj.AsStringUtf8();
             packer.PackString(temp);
         }
         else if (obj.IsTypeOf(typeof(Single)) == true)
         {
             float temp = obj.AsSingle();
             packer.Pack<float>(temp);
         }
         else if (obj.IsTypeOf(typeof(int)) == true)
         {
             int temp = obj.AsInt32();
             packer.Pack(temp);
         }
     }
 }
 protected override void PackToMessageCore(Packer packer)
 {
     packer.PackArrayHeader(1);
     packer.Pack(_str);
 }
        void Pack(Packer packer, object o)
        {
            if (o == null) {
                packer.PackNull();
                return;
            }

            if (o is int)
                packer.Pack ((int)o);
            else if (o is uint)
                packer.Pack ((uint)o);
            else if (o is float)
                packer.Pack ((float)o);
            else if (o is double)
                packer.Pack ((double)o);
            else if (o is long)
                packer.Pack ((long)o);
            else if (o is ulong)
                packer.Pack ((ulong)o);
            else if (o is bool)
                packer.Pack ((bool)o);
            else if (o is byte)
                packer.Pack ((byte)o);
            else if (o is sbyte)
                packer.Pack ((sbyte)o);
            else if (o is short)
                packer.Pack ((short)o);
            else if (o is ushort)
                packer.Pack ((ushort)o);
            else if (o is string)
                packer.PackString((string)o, Encoding.ASCII);
            else if (o is Dictionary<string, object>)
            {
                packer.PackMapHeader((o as Dictionary<string, object>).Count);

                foreach (var pair in (o as Dictionary<string, object>))
                {
                    Pack(packer, pair.Key);
                    Pack(packer, pair.Value);
                }

            }
            else if (o is string[])
            {
                packer.PackArrayHeader((o as string[]).Length);

                foreach (var obj in (o as string[]))
                    packer.Pack(obj as string);
            }
            else
                throw new Exception("Cant handle type: " + o.GetType().Name);;
        }