Пример #1
0
        public override void Randomize()
        {
            int    arraylength = -1;
            Random rand        = new Random();
            int    strlength;

            byte[] strbuf, myByte;

            //target
            target = new PointStamped();
            target.Randomize();
            //pointing_axis
            pointing_axis = new Vector3();
            pointing_axis.Randomize();
            //pointing_frame
            strlength = rand.Next(100) + 1;
            strbuf    = new byte[strlength];
            rand.NextBytes(strbuf);  //fill the whole buffer with random bytes
            for (int __x__ = 0; __x__ < strlength; __x__++)
            {
                if (strbuf[__x__] == 0) //replace null chars with non-null random ones
                {
                    strbuf[__x__] = (byte)(rand.Next(254) + 1);
                }
            }
            strbuf[strlength - 1] = 0; //null terminate
            pointing_frame        = Encoding.ASCII.GetString(strbuf);
            //min_duration
            min_duration = new Duration(new TimeData(
                                            Convert.ToUInt32(rand.Next()),
                                            Convert.ToUInt32(rand.Next())));
            //max_velocity
            max_velocity = (rand.Next() + rand.NextDouble());
        }
Пример #2
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;

            //target
            if (target == null)
            {
                target = new PointStamped();
            }
            pieces.Add(target.Serialize(true));
            //pointing_axis
            if (pointing_axis == null)
            {
                pointing_axis = new Vector3();
            }
            pieces.Add(pointing_axis.Serialize(true));
            //pointing_frame
            if (pointing_frame == null)
            {
                pointing_frame = "";
            }
            scratch1  = Encoding.ASCII.GetBytes((string)pointing_frame);
            thischunk = new byte[scratch1.Length + 4];
            scratch2  = BitConverter.GetBytes(scratch1.Length);
            Array.Copy(scratch1, 0, thischunk, 4, scratch1.Length);
            Array.Copy(scratch2, thischunk, 4);
            pieces.Add(thischunk);
            //min_duration
            pieces.Add(BitConverter.GetBytes(min_duration.data.sec));
            pieces.Add(BitConverter.GetBytes(min_duration.data.nsec));
            //max_velocity
            scratch1 = new byte[Marshal.SizeOf(typeof(double))];
            h        = GCHandle.Alloc(scratch1, GCHandleType.Pinned);
            Marshal.StructureToPtr(max_velocity, 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);
        }
Пример #3
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;

            //target
            target = new PointStamped(SERIALIZEDSTUFF, ref currentIndex);
            //pointing_axis
            pointing_axis = new Vector3(SERIALIZEDSTUFF, ref currentIndex);
            //pointing_frame
            pointing_frame = "";
            piecesize      = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex  += 4;
            pointing_frame = Encoding.ASCII.GetString(SERIALIZEDSTUFF, currentIndex, piecesize);
            currentIndex  += piecesize;
            //min_duration
            min_duration = new Duration(new TimeData(
                                            BitConverter.ToUInt32(SERIALIZEDSTUFF, currentIndex),
                                            BitConverter.ToUInt32(SERIALIZEDSTUFF, currentIndex + Marshal.SizeOf(typeof(System.Int32)))));
            currentIndex += 2 * Marshal.SizeOf(typeof(System.Int32));
            //max_velocity
            piecesize = Marshal.SizeOf(typeof(double));
            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");
            }
            max_velocity = (double)Marshal.PtrToStructure(h, typeof(double));
            Marshal.FreeHGlobal(h);
            currentIndex += piecesize;
        }