Ejemplo n.º 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;

            //names
            hasmetacomponents |= false;
            if (names == null)
            {
                names = new string[0];
            }
            pieces.Add(BitConverter.GetBytes(names.Length));
            for (int i = 0; i < names.Length; i++)
            {
                //names[i]
                if (names[i] == null)
                {
                    names[i] = "";
                }
                scratch1  = Encoding.ASCII.GetBytes((string)names[i]);
                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);
            }
            //states
            hasmetacomponents |= true;
            if (states == null)
            {
                states = new Messages.baxter_core_msgs.NavigatorState[0];
            }
            pieces.Add(BitConverter.GetBytes(states.Length));
            for (int i = 0; i < states.Length; i++)
            {
                //states[i]
                if (states[i] == null)
                {
                    states[i] = new Messages.baxter_core_msgs.NavigatorState();
                }
                pieces.Add(states[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);
        }
Ejemplo n.º 2
0
        public override void Randomize()
        {
            int    arraylength = -1;
            Random rand        = new Random();
            int    strlength;

            byte[] strbuf, myByte;

            //names
            arraylength = rand.Next(10);
            if (names == null)
            {
                names = new string[arraylength];
            }
            else
            {
                Array.Resize(ref names, arraylength);
            }
            for (int i = 0; i < names.Length; i++)
            {
                //names[i]
                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
                names[i] = Encoding.ASCII.GetString(strbuf);
            }
            //states
            arraylength = rand.Next(10);
            if (states == null)
            {
                states = new Messages.baxter_core_msgs.NavigatorState[arraylength];
            }
            else
            {
                Array.Resize(ref states, arraylength);
            }
            for (int i = 0; i < states.Length; i++)
            {
                //states[i]
                states[i] = new Messages.baxter_core_msgs.NavigatorState();
                states[i].Randomize();
            }
        }
Ejemplo n.º 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;

            //names
            hasmetacomponents |= false;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (names == null)
            {
                names = new string[arraylength];
            }
            else
            {
                Array.Resize(ref names, arraylength);
            }
            for (int i = 0; i < names.Length; i++)
            {
                //names[i]
                names[i]      = "";
                piecesize     = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
                currentIndex += 4;
                names[i]      = Encoding.ASCII.GetString(SERIALIZEDSTUFF, currentIndex, piecesize);
                currentIndex += piecesize;
            }
            //states
            hasmetacomponents |= true;
            arraylength        = BitConverter.ToInt32(SERIALIZEDSTUFF, currentIndex);
            currentIndex      += Marshal.SizeOf(typeof(System.Int32));
            if (states == null)
            {
                states = new Messages.baxter_core_msgs.NavigatorState[arraylength];
            }
            else
            {
                Array.Resize(ref states, arraylength);
            }
            for (int i = 0; i < states.Length; i++)
            {
                //states[i]
                states[i] = new Messages.baxter_core_msgs.NavigatorState(SERIALIZEDSTUFF, ref currentIndex);
            }
        }