public void Pack(Packer packer, object obj)
        {
            var sentinel = (IDisposeSentinel)obj;
            var type     = sentinel.GetType();

            Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(type.GetGenericTypeDefinition()));
            Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(type.GenericTypeArguments[0]));
            Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(type.GenericTypeArguments[1]));

            packer.PackInternal(sentinel.GetData());
            Int64Serializer.PackDirect(packer, sentinel.GetTick());
        }
Example #2
0
        public void Pack(Packer packer, object obj)
        {
            var dict = (ME.ECS.Collections.IDictionaryInt)obj;
            var type = dict.GetType();

            Int32Serializer.PackDirect(packer, dict.Count);

            Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(type.GenericTypeArguments[0]));
            Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(type.GetGenericTypeDefinition()));

            foreach (DictionaryEntry entry in dict)
            {
                packer.PackInternal(entry.Key);
                packer.PackInternal(entry.Value);
            }
        }
Example #3
0
        public void Pack(Packer packer, object obj)
        {
            var rootType = obj.GetType();
            var typeId   = packer.GetMetaTypeId(rootType);

            Int32Serializer.PackDirect(packer, typeId);

            this.Pack(packer, obj, rootType);
        }
        public void Pack(Packer packer, object obj)
        {
            var arr  = (IList)obj;
            var type = arr.GetType();

            Int32Serializer.PackDirect(packer, arr.Count);

            if (type.IsArray == true)
            {
                var rank = type.GetArrayRank();
                if (rank > 1)
                {
                    packer.WriteByte(2);
                }
                else
                {
                    packer.WriteByte(1);
                }

                Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(type.GetElementType()));

                if (rank > 1)
                {
                    Int32Serializer.PackDirect(packer, rank);
                    var arrData = (System.Array)arr;

                    for (int j = 0; j < rank; ++j)
                    {
                        Int32Serializer.PackDirect(packer, arrData.GetLength(j));
                    }

                    void WrapDimension(int[] ids, int currentDimension)
                    {
                        if (currentDimension == rank)
                        {
                            packer.PackInternal(arrData.GetValue(ids));
                        }
                        else
                        {
                            for (int i = 0, length = arrData.GetLength(currentDimension); i < length; i++)
                            {
                                ids[currentDimension] = i;
                                WrapDimension(ids, currentDimension + 1);
                            }
                        }
                    }

                    WrapDimension(new int[rank], 0);
                }
                else
                {
                    for (int i = 0; i < arr.Count; ++i)
                    {
                        packer.PackInternal(arr[i]);
                    }
                }
            }
            else
            {
                packer.WriteByte(0);
                Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(arr.GetType().GenericTypeArguments[0]));
                Int32Serializer.PackDirect(packer, packer.GetMetaTypeId(arr.GetType().GetGenericTypeDefinition()));

                for (int i = 0; i < arr.Count; ++i)
                {
                    packer.PackInternal(arr[i]);
                }
            }
        }