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

            byte[] strbuf, myByte;

            //header
            header = new Header();
            header.Randomize();
            //angle_min
            angle_min = (float)(rand.Next() + rand.NextDouble());
            //angle_max
            angle_max = (float)(rand.Next() + rand.NextDouble());
            //angle_increment
            angle_increment = (float)(rand.Next() + rand.NextDouble());
            //time_increment
            time_increment = (float)(rand.Next() + rand.NextDouble());
            //scan_time
            scan_time = (float)(rand.Next() + rand.NextDouble());
            //range_min
            range_min = (float)(rand.Next() + rand.NextDouble());
            //range_max
            range_max = (float)(rand.Next() + rand.NextDouble());
            //ranges
            arraylength = rand.Next(10);
            if (ranges == null)
            {
                ranges = new Messages.sensor_msgs.LaserEcho[arraylength];
            }
            else
            {
                Array.Resize(ref ranges, arraylength);
            }
            for (int i = 0; i < ranges.Length; i++)
            {
                //ranges[i]
                ranges[i] = new Messages.sensor_msgs.LaserEcho();
                ranges[i].Randomize();
            }
            //intensities
            arraylength = rand.Next(10);
            if (intensities == null)
            {
                intensities = new Messages.sensor_msgs.LaserEcho[arraylength];
            }
            else
            {
                Array.Resize(ref intensities, arraylength);
            }
            for (int i = 0; i < intensities.Length; i++)
            {
                //intensities[i]
                intensities[i] = new Messages.sensor_msgs.LaserEcho();
                intensities[i].Randomize();
            }
        }
        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;

            //header
            header = new Header(SERIALIZEDSTUFF, ref currentIndex);
            //angle_min
            piecesize = Marshal.SizeOf(typeof(Single));
            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");
            }
            angle_min = (Single)Marshal.PtrToStructure(h, typeof(Single));
            Marshal.FreeHGlobal(h);
            currentIndex += piecesize;
            //angle_max
            piecesize = Marshal.SizeOf(typeof(Single));
            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");
            }
            angle_max = (Single)Marshal.PtrToStructure(h, typeof(Single));
            Marshal.FreeHGlobal(h);
            currentIndex += piecesize;
            //angle_increment
            piecesize = Marshal.SizeOf(typeof(Single));
            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");
            }
            angle_increment = (Single)Marshal.PtrToStructure(h, typeof(Single));
            Marshal.FreeHGlobal(h);
            currentIndex += piecesize;
            //time_increment
            piecesize = Marshal.SizeOf(typeof(Single));
            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");
            }
            time_increment = (Single)Marshal.PtrToStructure(h, typeof(Single));
            Marshal.FreeHGlobal(h);
            currentIndex += piecesize;
            //scan_time
            piecesize = Marshal.SizeOf(typeof(Single));
            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");
            }
            scan_time = (Single)Marshal.PtrToStructure(h, typeof(Single));
            Marshal.FreeHGlobal(h);
            currentIndex += piecesize;
            //range_min
            piecesize = Marshal.SizeOf(typeof(Single));
            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");
            }
            range_min = (Single)Marshal.PtrToStructure(h, typeof(Single));
            Marshal.FreeHGlobal(h);
            currentIndex += piecesize;
            //range_max
            piecesize = Marshal.SizeOf(typeof(Single));
            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");
            }
            range_max = (Single)Marshal.PtrToStructure(h, typeof(Single));
            Marshal.FreeHGlobal(h);
            currentIndex += piecesize;
            //ranges
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (ranges == null)
            {
                ranges = new Messages.sensor_msgs.LaserEcho[arraylength];
            }
            else
            {
                Array.Resize(ref ranges, arraylength);
            }
            for (int i = 0; i < ranges.Length; i++)
            {
                //ranges[i]
                ranges[i] = new Messages.sensor_msgs.LaserEcho(SERIALIZEDSTUFF, ref currentIndex);
            }
            //intensities
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (intensities == null)
            {
                intensities = new Messages.sensor_msgs.LaserEcho[arraylength];
            }
            else
            {
                Array.Resize(ref intensities, arraylength);
            }
            for (int i = 0; i < intensities.Length; i++)
            {
                //intensities[i]
                intensities[i] = new Messages.sensor_msgs.LaserEcho(SERIALIZEDSTUFF, ref currentIndex);
            }
        }
        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;

            //header
            if (header == null)
            {
                header = new Header();
            }
            pieces.Add(header.Serialize(true));
            //angle_min
            scratch1 = new byte[Marshal.SizeOf(typeof(Single))];
            h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
            Marshal.StructureToPtr(angle_min, h.AddrOfPinnedObject(), false);
            h.Free();
            pieces.Add(scratch1);
            //angle_max
            scratch1 = new byte[Marshal.SizeOf(typeof(Single))];
            h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
            Marshal.StructureToPtr(angle_max, h.AddrOfPinnedObject(), false);
            h.Free();
            pieces.Add(scratch1);
            //angle_increment
            scratch1 = new byte[Marshal.SizeOf(typeof(Single))];
            h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
            Marshal.StructureToPtr(angle_increment, h.AddrOfPinnedObject(), false);
            h.Free();
            pieces.Add(scratch1);
            //time_increment
            scratch1 = new byte[Marshal.SizeOf(typeof(Single))];
            h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
            Marshal.StructureToPtr(time_increment, h.AddrOfPinnedObject(), false);
            h.Free();
            pieces.Add(scratch1);
            //scan_time
            scratch1 = new byte[Marshal.SizeOf(typeof(Single))];
            h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
            Marshal.StructureToPtr(scan_time, h.AddrOfPinnedObject(), false);
            h.Free();
            pieces.Add(scratch1);
            //range_min
            scratch1 = new byte[Marshal.SizeOf(typeof(Single))];
            h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
            Marshal.StructureToPtr(range_min, h.AddrOfPinnedObject(), false);
            h.Free();
            pieces.Add(scratch1);
            //range_max
            scratch1 = new byte[Marshal.SizeOf(typeof(Single))];
            h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
            Marshal.StructureToPtr(range_max, h.AddrOfPinnedObject(), false);
            h.Free();
            pieces.Add(scratch1);
            //ranges
            hasmetacomponents |= true;
            if (ranges == null)
            {
                ranges = new Messages.sensor_msgs.LaserEcho[0];
            }
            pieces.Add(BitConverter.GetBytes(ranges.Length));
            for (int i = 0; i < ranges.Length; i++)
            {
                //ranges[i]
                if (ranges[i] == null)
                {
                    ranges[i] = new Messages.sensor_msgs.LaserEcho();
                }
                pieces.Add(ranges[i].Serialize(true));
            }
            //intensities
            hasmetacomponents |= true;
            if (intensities == null)
            {
                intensities = new Messages.sensor_msgs.LaserEcho[0];
            }
            pieces.Add(BitConverter.GetBytes(intensities.Length));
            for (int i = 0; i < intensities.Length; i++)
            {
                //intensities[i]
                if (intensities[i] == null)
                {
                    intensities[i] = new Messages.sensor_msgs.LaserEcho();
                }
                pieces.Add(intensities[i].Serialize(true));
            }
            //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);
        }