예제 #1
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;

            //header
            if (header == null)
            {
                header = new Header();
            }
            pieces.Add(header.Serialize(true));
            //points
            hasmetacomponents |= true;
            if (points == null)
            {
                points = new Point32[0];
            }
            pieces.Add(BitConverter.GetBytes(points.Length));
            for (int i = 0; i < points.Length; i++)
            {
                //points[i]
                if (points[i] == null)
                {
                    points[i] = new Point32();
                }
                pieces.Add(points[i].Serialize(true));
            }
            //channels
            hasmetacomponents |= true;
            if (channels == null)
            {
                channels = new Messages.sensor_msgs.ChannelFloat32[0];
            }
            pieces.Add(BitConverter.GetBytes(channels.Length));
            for (int i = 0; i < channels.Length; i++)
            {
                //channels[i]
                if (channels[i] == null)
                {
                    channels[i] = new Messages.sensor_msgs.ChannelFloat32();
                }
                pieces.Add(channels[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);
        }
예제 #2
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;

            //header
            header = new Header(SERIALIZEDSTUFF, ref currentIndex);
            //points
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (points == null)
            {
                points = new Point32[arraylength];
            }
            else
            {
                Array.Resize(ref points, arraylength);
            }
            for (int i = 0; i < points.Length; i++)
            {
                //points[i]
                points[i] = new Point32(SERIALIZEDSTUFF, ref currentIndex);
            }
            //channels
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (channels == null)
            {
                channels = new Messages.sensor_msgs.ChannelFloat32[arraylength];
            }
            else
            {
                Array.Resize(ref channels, arraylength);
            }
            for (int i = 0; i < channels.Length; i++)
            {
                //channels[i]
                channels[i] = new Messages.sensor_msgs.ChannelFloat32(SERIALIZEDSTUFF, ref currentIndex);
            }
        }
예제 #3
0
        public override void Randomize()
        {
            int    arraylength = -1;
            Random rand        = new Random();
            int    strlength;

            byte[] strbuf, myByte;

            //header
            header = new Header();
            header.Randomize();
            //points
            arraylength = rand.Next(10);
            if (points == null)
            {
                points = new Point32[arraylength];
            }
            else
            {
                Array.Resize(ref points, arraylength);
            }
            for (int i = 0; i < points.Length; i++)
            {
                //points[i]
                points[i] = new Point32();
                points[i].Randomize();
            }
            //channels
            arraylength = rand.Next(10);
            if (channels == null)
            {
                channels = new Messages.sensor_msgs.ChannelFloat32[arraylength];
            }
            else
            {
                Array.Resize(ref channels, arraylength);
            }
            for (int i = 0; i < channels.Length; i++)
            {
                //channels[i]
                channels[i] = new Messages.sensor_msgs.ChannelFloat32();
                channels[i].Randomize();
            }
        }