public override void Randomize()
        {
            int    arraylength = -1;
            Random rand        = new Random();
            int    strlength;

            byte[] strbuf, myByte;

            //layout
            layout = new MultiArrayLayout();
            layout.Randomize();
            //data
            arraylength = rand.Next(10);
            if (data == null)
            {
                data = new byte[arraylength];
            }
            else
            {
                Array.Resize(ref data, arraylength);
            }
            for (int i = 0; i < data.Length; i++)
            {
                //data[i]
                myByte = new byte[1];
                rand.NextBytes(myByte);
                data[i] = myByte[0];
            }
        }
        public override void Deserialize(byte[] SERIALIZEDSTUFF, ref int currentIndex)
        {
            int    arraylength       = -1;
            bool   hasmetacomponents = false;
            object __thing;
            int    piecesize = 0;

            byte[] thischunk, scratch1, scratch2;
            IntPtr h;

            //layout
            layout = new MultiArrayLayout(SERIALIZEDSTUFF, ref currentIndex);
            //data
            hasmetacomponents |= false;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (data == null)
            {
                data = new byte[arraylength];
            }
            else
            {
                Array.Resize(ref data, arraylength);
            }
            Array.Copy(SERIALIZEDSTUFF, currentIndex, data, 0, data.Length);
            currentIndex += data.Length;
        }
        public override byte[] Serialize(bool partofsomethingelse)
        {
            int  currentIndex = 0, length = 0;
            bool hasmetacomponents = false;

            byte[]        thischunk, scratch1, scratch2;
            List <byte[]> pieces = new List <byte[]>();
            GCHandle      h;

            //layout
            if (layout == null)
            {
                layout = new MultiArrayLayout();
            }
            pieces.Add(layout.Serialize(true));
            //data
            hasmetacomponents |= false;
            if (data == null)
            {
                data = new byte[0];
            }
            pieces.Add(BitConverter.GetBytes(data.Length));
            pieces.Add((byte[])data);
            //combine every array in pieces into one array and return it
            int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length);
            int __a_b__e = 0;

            byte[] __a_b__d = new byte[__a_b__f];
            foreach (var __p__ in pieces)
            {
                Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length);
                __a_b__e += __p__.Length;
            }
            return(__a_b__d);
        }
Example #4
0
        public override void Randomize()
        {
            int    arraylength = -1;
            Random rand        = new Random();
            int    strlength;

            byte[] strbuf, myByte;

            //layout
            layout = new MultiArrayLayout();
            layout.Randomize();
            //data
            arraylength = rand.Next(10);
            if (data == null)
            {
                data = new long[arraylength];
            }
            else
            {
                Array.Resize(ref data, arraylength);
            }
            for (int i = 0; i < data.Length; i++)
            {
                //data[i]
                data[i] = (System.Int64)(rand.Next() << 32) | rand.Next();
            }
        }
Example #5
0
        public override void Randomize()
        {
            int    arraylength = -1;
            Random rand        = new Random();
            int    strlength;

            byte[] strbuf, myByte;

            //layout
            layout = new MultiArrayLayout();
            layout.Randomize();
            //data
            arraylength = rand.Next(10);
            if (data == null)
            {
                data = new Single[arraylength];
            }
            else
            {
                Array.Resize(ref data, arraylength);
            }
            for (int i = 0; i < data.Length; i++)
            {
                //data[i]
                data[i] = (float)(rand.Next() + rand.NextDouble());
            }
        }
Example #6
0
        public override void Deserialize(byte[] SERIALIZEDSTUFF, ref int currentIndex)
        {
            int    arraylength       = -1;
            bool   hasmetacomponents = false;
            object __thing;
            int    piecesize = 0;

            byte[] thischunk, scratch1, scratch2;
            IntPtr h;

            //layout
            layout = new MultiArrayLayout(SERIALIZEDSTUFF, ref currentIndex);
            //data
            hasmetacomponents |= false;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (data == null)
            {
                data = new long[arraylength];
            }
            else
            {
                Array.Resize(ref data, arraylength);
            }
            for (int i = 0; i < data.Length; i++)
            {
                //data[i]
                piecesize = Marshal.SizeOf(typeof(long));
                h         = IntPtr.Zero;
                if (SERIALIZEDSTUFF.Length - currentIndex != 0)
                {
                    h = Marshal.AllocHGlobal(piecesize);
                    Marshal.Copy(SERIALIZEDSTUFF, currentIndex, h, piecesize);
                }
                if (h == IntPtr.Zero)
                {
                    throw new Exception("Alloc failed");
                }
                data[i] = (long)Marshal.PtrToStructure(h, typeof(long));
                Marshal.FreeHGlobal(h);
                currentIndex += piecesize;
            }
        }
Example #7
0
        public override byte[] Serialize(bool partofsomethingelse)
        {
            int  currentIndex = 0, length = 0;
            bool hasmetacomponents = false;

            byte[]        thischunk, scratch1, scratch2;
            List <byte[]> pieces = new List <byte[]>();
            GCHandle      h;

            //layout
            if (layout == null)
            {
                layout = new MultiArrayLayout();
            }
            pieces.Add(layout.Serialize(true));
            //data
            hasmetacomponents |= false;
            if (data == null)
            {
                data = new long[0];
            }
            pieces.Add(BitConverter.GetBytes(data.Length));
            for (int i = 0; i < data.Length; i++)
            {
                //data[i]
                scratch1 = new byte[Marshal.SizeOf(typeof(long))];
                h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
                Marshal.StructureToPtr(data[i], h.AddrOfPinnedObject(), false);
                h.Free();
                pieces.Add(scratch1);
            }
            //combine every array in pieces into one array and return it
            int __a_b__f = pieces.Sum((__a_b__c) => __a_b__c.Length);
            int __a_b__e = 0;

            byte[] __a_b__d = new byte[__a_b__f];
            foreach (var __p__ in pieces)
            {
                Array.Copy(__p__, 0, __a_b__d, __a_b__e, __p__.Length);
                __a_b__e += __p__.Length;
            }
            return(__a_b__d);
        }